Time and date display


I have a problem with translating date display, from English into Danish. The month is not translated in the Danish date display. Does anyone know how it can be done.

In the language file there is a translation of months with 'date: month: 01' => 'January% s', etc., but the translation is not used in the general date display.





  • Hi gillie in the language file you will see a line something like this

    'friendlytime:date_format' => 'j F Y @ g:ia',

    I don't know how to translate the months to other languages but you could choose a different format

    here is the table of php time date settings http://php.net/manual/en/function.date.php


  • Thank you, Susan.

    I'm afraid it's not that simple. F in the dateformat is what I want, a full textual representation of a month. But in php a danish substitute for F doesn't exist.

    I use j. F Y | H:i which display 2. July 2010 | 11:00. In danish the months are in lower case and spelled different so it should be - 2. juli 2010 | 11.00.

    I could translate the month and put them in the language file but how would I display them? So in a way date display is partly hardcoded in elgg. The substring F is not in any language files but one.

    If you look at for example "Blogs" you'll see a monthly archive in left side menu with translation of months. That's what I would like. Those months are translated in the main language file and displayed correctly.

    I was hoping that a skilled coder could give me some guidance.



  • @Gilllie:) actually I have the same problem - I would be very happy to receive guidance on how to deal with the date time translation correctly, instead of just trying to work round it.  My network is in Hebrew which means a completely different alphabet and language direction

  • Did you try to read new view (views/default/output/friendlytime.php ) and read code in order to detect, who and where write date in the title of link?

  • OK, catch it. Never trust Eglish-speaking people to write good 18n'able code. Extractions from output/friendlytime.php

    $timestamp = htmlentities(date(elgg_echo('friendlytime:date_format'), $vars['time']));

    but PHP:date - Manual in pure English clearly states

    To format dates in other (non-English /my note/) languages, you should use the setlocale() and strftime() functions instead of date()


    1. if setlocale() already set somewhere (I'm too lazy to verify code, you see good or bad result after test), you have to

    • change friendlytime:date_format according to strftime format spec;
    • change $timestamp definition to
      $timestamp = htmlentities(strftime(elgg_echo('friendlytime:date_format'), $vars['time']));

    2. if setlocale not defined (1-st test return unwanted text) you have to add

    setlocale(LC_TIME, 'localecode');

    before $timestamp definition in addition to previous changes

    PS - "The Right Way" (tm) will be perform all these actions in own custom theme, where you can safe redefine default views

    PPS - even The More Right Way will be to fill bug-report to Trac also

  • You can override the view that Alexander pointed out and use something like this:

    $oldLocale = setlocale(LC_TIME, 'fr_FR.UTF-8');
    $timestamp = strftime("%a %d %b %Y", $vars['time']);
    setlocale(LC_TIME, $oldLocale);

    You need to make sure that the locale you use is installed on your server.

    Edit: As Alexander so graciously points out below, I'm wrong about the return value of setlocale.

  • Ah, I see Alexander already beat me to it.

  • Thank you all. I will try to figure it out :)

  • @all
    seems we're all tripping over over own feet to get this code right..
    I've put up a few examples here -->
    just playing around with the code ;-)

  • 2Cash:

    $oldLocale = setlocale(LC_TIME, 'fr_FR.UTF-8');


    RTFM from setlocale:

    Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.