All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Localization: month names for Low Events in German or English possible, depending on context?

Rene 11 Nov 2012 15:06 question, complete

Hi,

I'm managing seminar dates with Low Events, and have a context in German and one in English to show a calendar with the seminars. If I get that right, Low Events takes the formatting of the months from the EE General Configuration Settings, which are set in German in my case.

Is there a way way to override that setting for those templates that show the English content, so they get the English month names?

Replies

  1. Low 12 Nov 2012 07:25

    Not possible out of the box at the moment, but I'll look into it as a feature request.

    In the meantime, there might be an add-on that sets the default language on a per-template basis. I've heard of one for EE1, anyway. Not sure if it's available for EE2.

  2. Rene 12 Nov 2012 14:41

    I've found the Date/Time Language Converter by Hippo http://www.madebyhippo.com/addons which works for EE date tags by encapsulating it like this:

    {exp:datetime_convert language="fr_FR" format="$A %e %B %Y"}{entry_date}{/exp:datetime_convert}

    Unfotunately, it's not working when I encapsulate a Low Event tag like {seminar_datum:end_date} instead of {entry_date}

    The plugin code looks rather simple:

     
    function datetime_convert()
    {
    $this->EE =& get_instance();

    header('Content-Type: text/html; charset=utf-8');

    $language=$this->EE->TMPL->fetch_param('language');
    $format = $this->EE->TMPL->fetch_param('format');

    $olddate = $this->EE->TMPL->tagdata;

    setlocale(LC_ALL, $language);

    $trans = get_html_translation_table(HTML_ENTITIES);

    $newdate = strtr(strftime($format,$olddate), $trans);

    $this->return_data = $newdate;
    }


    Do you see what I would have to change to make it work with Low Events tags?

  3. Low 12 Nov 2012 16:09

    You could either try and use {seminar_datum:end_date format="%U"} to return a Unix timestamp, or alter Hippo's plugin by adding the following line after $olddate = $this->EE->TMPL->tagdata:

    if ( ! is_numeric($olddate)) $olddate = strtotime($olddate);

  4. Rene 12 Nov 2012 17:03

    Low, you're a genius, both options work! Thanks a lot!

    One minor problem remains: your solution is not working for the archive tags. Any idea how to get around that, and get "Oct" out of {month_short} or {month} instead of "Okt"?

    It seems the formatting for the archive tags is already done in your plugin, so Hippo's plugin doesn't find an Unix timestamp to process there.

    I use the archive tag to build a navigation showing the events per a given month.

  5. Low 12 Nov 2012 21:29

    You could use the tags to output something like 2012-11-01 and wrap that around Hippo's plugin to translate, as long as it has the addition I mentioned previously.

  6. Rene 12 Nov 2012 22:29

    Your again showing the way, Low! I had to use {date_url} to make it work. To post a summary as a reference for others who have to solve the same problem:

    1. Get the Date/Time Language Converter Plugin by Hippo from here: http://www.madebyhippo.com/addons

    2. If you don't need the archive tag from Low Events, you can install the plugin and use this method:

    {exp:datetime_convert language="en_EN" format="%e %b %Y"}{event_dates:start_date format="%U"}{/exp:datetime_convert}

    Explanation: This works by passing the appropriate language reference into the language=" " parameter, of the plugin tag, like de_DE for German, fr_FR for French, en_EN for English, etc.

    For formatting the output use the php stfrtime parameters:

    http://php.net/manual/en/function.str...

    In the Low Event tag, use the format="%U" (Unix timestamp), so the Date/Time Converter plugin gets the right time format to work with.

    3. If you want to use the Low Events archive tag as well, look for this line in the Hippo plugin:

    $olddate = $this->EE->TMPL->tagdata;

    and add this line immediately afterwards:

    if ( ! is_numeric($olddate)) $olddate = strtotime($olddate);

    With this hack in place, you no longer need to add format="%U" to your Low Event tag, you can just use {event_dates:start_date} and encapsulate it with the Hippo plugin tags like shown above, and format the output as desired with the PHP stfrtime parameters.

    4. For the archive tag of Low Events, encapsulate {date_url} with the plugin code:

    {exp:datetime_convert language="en_EN" format="%b %Y"}{date_url}{/exp:datetime_convert}

    This will output month names as "Dec 2012", if you want "December 2012", use format="%B %Y" instead, and if you want "Dezember 2012", you have to use language "de_DE" for German.

    Hope that makes sense for everyone and I'm glad for this workaround, for my project.

    Thanks again Low for your help - and I hope we can soon just use something like locale="de_DE" directly in the Low Events tag! :)