Home › Forums › Calendar Products › Events Calendar PRO › Date display with WPML
- This topic has 9 replies, 3 voices, and was last updated 11 years, 9 months ago by Rob.
-
AuthorPosts
-
July 13, 2012 at 3:18 pm #22090JenParticipant
Hi guys! I’m installing WPML on my site. I was quite happy to see the strings already translated! One thing I noticed, though, is that the dates themselves are still in English, showing “Friday, August 3” instead of “viernes, agosto 3,” for instance. I am able to work around it in some places using a combination of get_bloginfo(‘language’), setlocale(), strtotime() and strftime(), but I was wondering if y’all could fix it in an upcoming update. Because my approach is a mess. Unless there’s an easy way I’m missing?
July 14, 2012 at 3:47 pm #22112Joyce GraceMemberHi Jen, which language are you trying to get translated? I can only see if we have that language translation file already (or you could even check). Some parts of it are controlled by WordPress itself, so you’d have to get translation files for that too.
Let me know if this is what you are asking – not sure if I get your question completely, or if you’ve already tried all of the above.
July 14, 2012 at 4:56 pm #22120JenParticipantSpanish, but it’s not an issue with the language translation file (which is present and working fine), it’s an issue with how the timestamps are being converted into strings. Currently it’s done with date() instead of with setlocale() and strftime().
July 14, 2012 at 4:59 pm #22122Joyce GraceMemberHi Jen, I will see if someone else can help, since I’m not familiar with this topic.
July 19, 2012 at 10:45 am #22406JenParticipantFor reference, here’s my totally inelegant workaround. In my header, I’m placing the following:
$lang = str_replace(“-“, “_”, get_bloginfo(‘language’));
setlocale(LC_ALL, $lang);Then, for instance, if I wanted to print out the start date of an event, I’d use the following:
$eventstartdate = tribe_get_start_date($post->ID, false);
$strformat = “%A, %B %e”;
if (strtoupper(substr(PHP_OS, 0, 3)) == ‘WIN’) {
$strformat = preg_replace(‘#(?<!%)((?:%%)*)%e#', '\1%#d', $strformat);
}
echo strftime($strformat, strtotime($eventstartdate));July 19, 2012 at 10:48 am #22408JenParticipantAnd already I’m improving it. Seems WordPress has a get_locale() function that eliminates that nonsense I’m doing with get_bloginfo(). The new header code would be setlocale(LC_ALL, get_locale());
July 20, 2012 at 3:09 pm #22483JenParticipantOK, I did lots more research and learned more about internationalization! Throw out everything I’ve written above. Using setlocale() is apparently bad for a number of reasons, and WordPress has a function date_i18n() for this purpose. After installing the Spanish-language .MO files from WordPress, I was able to use this one function to fix the problem. Instead of all that above, I can get the same result with the following:
echo date_i18n(‘F j, Y’, strtotime(tribe_get_start_date($post->ID, false));July 20, 2012 at 3:11 pm #22484JenParticipantOh, and by “fix the problem,” I mean that I worked around it in a few places. This still needs to be implemented widely within the Events Calendar.
July 20, 2012 at 3:44 pm #22487JenParticipantJoyce, I’m an absolute idiot. Y’all have it implemented correctly. The reason it wasn’t working was because I hadn’t installed those WordPress .MO files. Please close this topic, and delete it to hide my idiocy! 😉
July 24, 2012 at 10:57 am #22634RobMemberHey Jen! Thanks for confirming as much, and apologies to hear this thread went dormant for a while. Joyce is out for the next week or so and we’re a bit understaffed on the support side.
But! I’m glad to hear you got this figured out and that you’re set on the core issue here. I am closing the thread accordingly. As always, let us know if you need anything else down the road 🙂
-
AuthorPosts
- The topic ‘Date display with WPML’ is closed to new replies.