Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us


Dates localization

edited June 2010 in Localization
How do i translate month names?
Tagged:
«1

Comments

  • edited June 2010
    I would be very interested in this, too!

    Most likely I found the reason, why you cannot localize Months & Days (yet): http://github.com/vanillaforums/Garden/commit/ce6c2600a98ed2a8571424edc3c74fb42e1891ed#commitcomment-98474
  • do you think it is possible to make a small patched file for the time being?
    or manually edit necessary lines?
    joe85
  • as i understand it gets it from the mysql, right?
  • SS
    edited February 2011
    Windows:
    http://php.net/manual/en/function.setlocale.php
    On Windows, setlocale(LC_ALL, '') sets the locale names from the system's regional/language settings (accessible via Control Panel).

    // Test on Linux
    locale -a
    no_NO.UTF-8
    pl_PL.ISO8859-2
    pl_PL.UTF-8
    pt_BR.ISO8859-1
    pt_BR.UTF-8
    ....
    =>
    setlocale($LocaleName. '.'. $Encoding);

    // php script
    $x[] = setlocale(LC_ALL, 'sk_SK'); //
    $CurrentLocale = Gdn::Config('Garden.Locale', 'en-CA');
    setlocale(LC_ALL, str_replace('-', '_', $CurrentLocale));
    Fail.
  • @lukoie wrote:
    do you think it is possible to make a small patched file for the time being?
    Yes it would be possible. But as this is a Core function of Vanilla, I think the developers should address it properly.
  • I think the best solution would be to make gdn::Format->Date overridable as many other functions, such as Plural, since setting proper locale does not do the job for some languages (it would be better to format text in different way). For instance, in russian locale-formatted string looks like, say, "Июнь 24", while proper way is "24 июня".
  • SS
    edited June 2010
    Gdn_Format::Date() uses strftime() which can display month in genitive case. Use token %B. However, I think that anyway need to make overridable Format::Date() function, +1 @TiGR

    http://vanillaforums.org/blog/translation-improvements-in-vanilla-2/comment-page-1/#comment-2238
  • @S token %B does not return month in genitive case on various server configurations (quite common problem, btw, AFAIK it works better only on FreeBSD servers, all linux servers return nominative form).

    Here is more information about various locale-related bugs in PHP: http://www.onphp5.com/article/22
  • SS
    edited June 2010
    @TiGR. Therefore, I have FreeBSD :p
    It is the only thing to do - modify your theme
    Gdn_Format::Date($Comment->DateInserted) -> 
    Gdn_Format::To($Comment->DateInserted, 'CustomFormatMethod')
  • The problem is that Gdn_Format::Date() calls are located not only in theme.

    P.S: We can't add FreeBSD as a requirement for Vanilla, right? Then we need function override.
  • At this point I want throw in the initial question to the discussion
    How do i translate month names?
  • phreakphreak VanillaSkins.com - #1 Themeshop for Vanilla ✭✭✭
    Hi all,

    I'm interested as well in the date change issue. Can someone hep translate "S"'s idea into something that easier to understand and implement for the time beeing?

    Thanx

    http://www.VanillaSkins.com - Great Themes For Just $15! :: Also check: Businessdads Plugins

  • TimTim Lord of Servers Vanilla Staff
    We've made some changes in RC3 that make our calls to setlocale() more sensible. In theory, this should clear up a lot of these issues.

    Vanilla Forums Senior Developer [GitHub, Twitter, About.me]

  • TiGRTiGR New
    edited July 2010
    @Tim, I don't see any changes that could solve the problem discussed (on current git). What do you mean exactly?
  • I would be eagerly interested in a simple answer to the initial question.
    Furthermore: is there a setting to change date and time format?
  • good question. how can I change this? time and date ...
    Does anyone have an idea? :)
  • Please help! Are there any solution?
  • Sorry to resurrect an old discussion, but... Is it possible to have the month names translated somehow?
  • ToddTodd Chief Product Officer Vanilla Staff
    I don't believe so at this time. We'll take a pull request though.
  • Would be great!
  • This small workaround below will ease the pain for the time being.

    In bootstrap.php, look for:
    $SetLocale = str_replace('-', '_', CurrentLocale).'.'.$Codeset;
    setlocale(LC_ALL, $SetLocale);

    Change to:
    $SetLocale = str_replace('-', '_', CurrentLocale).'.'.$Codeset;
    if ($CurrentLocale == 'hu') setlocale(LC_ALL, $SetLocale, 'hungarian');
    else setlocale(LC_ALL, $SetLocale);
    //setlocale(LC_ALL, $SetLocale);

    In library/core/class.format.php, look for:
    return strftime($Format, $Timestamp);

    Change to:
    return iconv('ISO-8859-2', 'UTF-8', strftime($Format, $Timestamp));
    //return strftime($Format, $Timestamp);


    Don't forget to change language code, name and code page to your language!
  • The previous solution doesn't work on 2.0.18.1.
    return strftime($Format, $Timestamp);
    is changed to $Result = strftime($Format, $Timestamp);
    or it doesn't exist?
    Is it possible to have the month names translated somehow?
  • How can i change "desember 22" to: "22 desember" ? All i want is to swap the order of month and day in LastCommentDate.

    Thanks in advance. :)

  • phreakphreak VanillaSkins.com - #1 Themeshop for Vanilla ✭✭✭

    changing setlocale variables in bootsstrap.php doesn't take effect. where do i need to make these changes to change month names? anyone has some help for me?

    http://www.VanillaSkins.com - Great Themes For Just $15! :: Also check: Businessdads Plugins

  • speaking of dates, anyone know how i can change like 9:04 to Today 9:04 if it shows up todays time instead of a full date? (wich is given out by Gdn_Format::Date($this->User->DateFirstVisit) in the user profile at example)

  • Using setlocale() does not appear a good solution to me. As explained in the documentaiton, this function is process-wide, which means that on multithreaded Apache implementations, calling it may change the locale in other active threads. This can be a problem if your Apache server runs other services than Garden/Vanilla.

    I did the following to solve this problem using Vanilla 2.0.18.1. It works by processing in PHP some of the date format placeholders (%a %A %b and %B)

    Some of you may find it a bit complex or overkilll, but it works properly in any environment. I am not a Vanilla developer, but of course the following code may be modified and included wherever anyone may need it.

    Step 1 : create arrays for month and day names in the standard locale

    In Garden/applications/dashboard/locale/en-CA/definitions.php look for :

    $Definition['Date.DefaultDateTimeFormat'] = '%B %e, %Y %l:%M%p';

    Insert after it

    $Definition['Date.WeekdayNames'] = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday");
    $Definition['Date.WeekdayShortNames'] = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri","Sat");
    $Definition['Date.MonthNames'] = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $Definition['Date.MonthShortNames'] = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
    

    Step 2 : Modify Date_format to use those arrays

    Modify library/core/class.format.php to use those arrays

    Look for

    if (strpos($Format, '%e') !== false)
    $Format = str_replace('%e', ltrim(strftime('%d', $Timestamp), '0'), $Format);
    

    After those lines, insert :

      if (strpos($Format, '%B') !== false)
      { // month names
        $MonthNames =    T('Date.MonthNames');
        $Format = str_replace('%B', $MonthNames[date("n", $Timestamp) - 1], $Format);
      }  
      if (strpos($Format, '%b') !== false)
      { // short month names
        $MonthShortNames =    T('Date.MonthShortNames');
        $Format = str_replace('%b', $MonthShortNames[date("n", $Timestamp) - 1], $Format);
      } 
      if (strpos($Format, '%A') !== false)
      { // long day names             
        $WeekdayNames =    T('Date.WeekdayNames');
        $Format = str_replace('%A', $WeekdayNames[date("w", $Timestamp)], $Format);
      }   
      if (strpos($Format, '%a') !== false)
      { // short day names
        $WeekdayShortName = T('Date.WeekdayShortNames');
        // $Format = str_replace('%a', $JourCourt[date("w", $Timestamp)], $Format);  
        $Format = str_replace('%a', $WeekdayShortName[date("w", $Timestamp)], $Format);
      }
    

    Step 3 : translate the month names

    In your locale, translate the arrays

    For example in french :

    $Definition['Date.WeekdayNames'] = array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi","Samedi"); 
    $Definition['Date.WeekdayShortNames'] = array("Dim", "Lun", "Mar", "Mer", "Jeu", "Ven","Sam");
    $Definition['Date.MonthNames'] = array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
    $Definition['Date.MonthShortNames'] = array("Jan", "Fév", "Mar", "Avr", "Mai", "Juin", "Juil", "Août", "Sept", "Oct", "Nov", "Déc");
    
    oliverradunerjackeyThorbjorn
  • 422422 Developer MVP
    edited January 2012

    Brilliant reply

    422 Real Estate Australia , now open Check it out

  • It doesn't work for me. Instead month names, show only one letter.

    Anyone else tried Olivier_Chevet's instructions?

  • I realized I forgot a step 4 in my instructions.

    Step 4 : add english translations for months

    you need to add the month names in English. Several location are possible. I came up with the following.

    in the file application/dashboad/locale/en-CA/definitions.php look for

    $Definition['Date.DefaultDateTimeFormat'] = '%B %e, %Y %l:%M%p';

    After this line, add :

    $Definition['Date.WeekdayNames'] = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday"); 
    $Definition['Date.WeekdayShortNames'] = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri","Sat");
    $Definition['Date.MonthNames'] = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $Definition['Date.MonthShortNames'] = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
    

    @MacWebsk in which language are you experiencing your problem ? Does it occur both for long and short month names ? I checked again and it works on my dev and production sites.

«1
Sign In or Register to comment.