Date display with WPML

Home Forums Calendar Products Events Calendar PRO Date display with WPML

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #22090
    Jen
    Participant

    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?

    #22112
    Joyce Grace
    Member

    Hi 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.

    #22120
    Jen
    Participant

    Spanish, 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().

    #22122
    Joyce Grace
    Member

    Hi Jen, I will see if someone else can help, since I’m not familiar with this topic.

    #22406
    Jen
    Participant

    For 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));

    #22408
    Jen
    Participant

    And 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());

    #22483
    Jen
    Participant

    OK, 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));

    #22484
    Jen
    Participant

    Oh, 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.

    #22487
    Jen
    Participant

    Joyce, 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! 😉

    #22634
    Rob
    Member

    Hey 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 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Date display with WPML’ is closed to new replies.