subscribe to the RSS Feed

Saturday, January 19, 2019

How to Qtranslate the German Date in this purple Tem plate?

Posted by Admin on Saturday, August 22nd, 2009

Last night I was spending quite some time figuring out how to get qtranslate translate the Dates of posts and the current date on the upper right of my purple tem plate correctly. As you can see, I somehow managed, but I have to confess that I was reaching through trial and error and finally applying some methods which may make somebody more PHP savvy than me raise his/her eyebrows: I have actually hardcoded the words “Posted by” and “on” into the german analogs “Gepostet durch” and “am” into the template files by using an if/else statement with ‘qtrans_getLanguage()’ function. A similar statement I used to get the actual date and the slogan in the header translated. I realized, that many people seem to experience some difficulties with date/time in qtranslate and I just want to share my experiences here as it might be useful to somebody else experiencing the same dfficulties.

I this template the posting dates are coded as the_date() and the actual date is called by date().

the_date() function in the posts translates dates without difficulties with my chosen settings, but I could not get qtranslate to translate date() in the header section and as I already mentioned, my knowledge of PHP is quite limited, so I could – inspite of all trials – not getting anything to work apart from using strftime() for the actual date.

My settings in qtranslate are as follows:

in Settings/Language/Avanced Settings/Date Time Conversion I selected “use emulated date function” and I edited the Language file like this: For German I enter ‘l, j. F, Y’ (without quotes) into the date field (time field can remain unchanged in my case, as I don’t use time indication). For English I enter ‘l, F jS, Y’ (without quotes – and again I don’t bother about time).

The if/else statements applied look like this:

to translate text / date in the posting date

<?php if (qtrans_getLanguage() == “en”) _e(‘Posted by’); else _e(‘Gepostet durch’)?> <?php the_author(); ?> <?php if (qtrans_getLanguage() == “en”) _e(‘on’); else _e(‘am’)?> <?php the_date(); ?>

to translate the actualdate

<?php if (qtrans_getLanguage() == “en”) echo date(‘l, F j, Y’) ; else echo strftime(‘%A, %d. %B %Y’); ?>

I find it rather cool that I can translate the Header slogan with this method too:

<?php if (qtrans_getLanguage() == “en”) bloginfo(‘description’); else _e(‘ENERGIE – subtil bis grob’) ; ?>

Final remark: above said – it all applies with my theme and my two languages English and German and I am in no way able to go beyond that in my explanations: I am sorry I just don’t have the time, FREE ENERGY or the in-depth knowledge to answer questions any better in the comments. However you can ask them anyway, some genius might come across to answer them for me…

I feel it like Edison, when he failed a thousand times to create his light bulp and finally had a bright result – though I preferred I could do like Nikola Tesla who just figured it all out in his mind and every of his creations, when translated to the material plane, just worked on the first attempt.