HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Dates localization

2

Comments

  • 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 Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    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?

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • 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");
    
  • 422422 Developer MVP
    edited January 2012

    Brilliant reply

    There was an error rendering this rich post.

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

  • you don't have to use arrays, just set your config file (conf/config.php)
    insert new line anywhere like this:

    $Configuration['Garden']['Locale'] = 'hu-HU';

    (this means all names will be hungarian)

  • @Olivier_Chevet hi, step 4 of your instructions is the same with step 1?

    My long month names (Slovak) are visible just as one letter. I follow your 3 steps instructions carefuly.

    check my forum site pls: macweb.sk/forum/

    thanks

  • @jungica: ok, solved, thank you very much mate. :) koszonom

  • @jungica: nice fix, but the order is still backwards...

    Right now, it says "februar 13" when i need "13 februar".

    Any way to change the order? :)

    Thanks in advance.

  • Turbolego said:
    Right now, it says "februar 13" when i need "13 februar".

    which language do you want to use?

  • Norwegian (nb_NO)

    jungica said:

    Turbolego said:
    Right now, it says "februar 13" when i need "13 februar".

    which language do you want to use?

  • jungicajungica New
    edited February 2012

    put into config: $Configuration['Garden']['Locale'] = 'nb_NO'; and search for the time display and change

    "%B %d"

    (februar 13)

    to

    "%d %B"

    (13 februar)

  • I added "$Configuration['Garden']['Locale'] = 'nb_NO';" to /conf/config.php, and it shows norwegian month names perfectly.

    But there are no "%B" or "%d" in the entire /conf/config.php document.

    Could you post your time display code?

    jungica said:
    put into config: $Configuration['Garden']['Locale'] = 'nb_NO'; and search for the time display and change

    "%B %d"

    (februar 13)

    to

    "%d %B"

    (13 februar)

  • jungicajungica New
    edited February 2012

    try library\core\class.format.php line 468?
    or library\core\functions.general.php line 927?

  • jungica said:

    try library\core\class.format.php line 468?

    Found this when i searched for %B:

           // If the timestamp is the same year, show the month and date
    
            $Format = T('Date.DefaultDayFormat', '%B %e');
         } else if (date('Y', $Timestamp) != date('Y', $Now)) {
            // If the timestamp is not the same year, just show the year
            $Format = T('Date.DefaultYearFormat', '%B %Y');
         } else {
            // Otherwise, use the date format
            $Format = T('Date.DefaultFormat', '%B %e, %Y');
         }
    

    Found this when i searched for %d:

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

    or library\core\functions.general.php line 927?

    Found this when i searched for %B:

              case 'medium':
    
                  $Result = Gdn_Format::Date($Value, '%e %b %Y');
                  break;
               case 'long':
                  $Result = Gdn_Format::Date($Value, '%e %B %Y');
                  break;
    

    Found this when i searched for %d:

    $Result = Gdn_Format::Date($Value, '%d/%m/%Y');

    Did not find anything in either documents when i searched for %B %d.

    Please advice.

Sign In or Register to comment.