For a Website (Wordpress) I want to display dates with the well-known plugin Meta Box and the Website should be provided in English as well as in German, with the plugin qTranslate.
German and English date formats are different: German: dd.mm.y (31.12.16), English: mm/dd/y (12/31/16). So to display the right format according to the language chosen by/for the visitor, the two plugins need to work together.
This is how I would display the date without any language option:
<?php echo rwmb_meta( 'exhibition_meta_beginning' ); ?>
This is how I would display translating text on the website outside of the post- and page-contents (like the site navigation):
<?php _e("[:en]Current[:de]Aktuell[:]"); ?>
My question now is, how I can join the two functions. If it helps, I would be fine with splitting the exhibition_meta_beginning in exhibition_meta_beginning_DE and exhibition_meta_beginning_EN, which would mean that I had to enter every date twice when creating a new instance/post, one in German and once in English format.
I haven't found anything useful yet – yes, there are mentions of that and there is some kind of way to use Custom Fields (which is the core basis of Meta Box) with qTranslate, but nothing seems to work and my knowledge in PHP is the bare minimum.
The input fields for the meta data being dates (and times) are defined in a separate PHP file like this (standard Meta Box procedure):
array(
'name' => 'Beginn der Ausstellung',
'id' => $prefix . 'beginn',
'type' => 'date',
'format' => 'dd.mm.y'
),
Neither did it work to implement the bilinguality into the format value right there (it thinks that it is a date's format not a language tag when [:en]... appears there), nor something like that in the part where the data is displayed (sorry for the amateurish attempt):
<?php __("[:en] echo rwmb_meta( 'exhibition_meta_beginn_EN' )[:de]echo rwmb_meta( 'exhibition_meta_beginn_DE' )[:]"); ?>
Thanks!
You can do it like this,
$en = rwmb_meta( 'exhibition_meta_beginn_EN' );
$de = rwmb_meta( 'exhibition_meta_beginn_DE' );
echo __('[:en]'.$en.'[:de]'.$de.'[:]');
or create a function that return the value based on language
function __show_based_on_lang($en, $de) {
return ( qtranxf_getLanguage() == 'en') ? $en : $de ;
}
then to use the function you can just have it like this,
echo __show_based_on_lang( rwmb_meta( 'exhibition_meta_beginn_EN' ), rwmb_meta( 'exhibition_meta_beginn_DE' ) );