We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    [Update: for MODX 2.2.4 (or higher) users, see my latest post at the bottom of this page]
    For < 2.2.4 users, read below:

    I searched ages for this: How to change the output language of date notations(day and month) in MODx. I finally found out how! (That cultureKey thingy in MODx is not working for me).

    So, for example:

    [[+publishedon:strtotime:date=`%A %e %B %Y`]]


    (Note: above date is php strftime notation, not php date notation!, see http://php.net/manual/en/function.strftime.php)


    Would output: wednesday 4 may 2011. To make it output in (for example) Dutch like: woensdag 4 mei 2011 you have to open config.core.php and add one of the following lines. The one you have to add depends on the brand of webserver your MODx installation runs on:

    Universal (?):
    setlocale(LC_ALL,'nl_NL.UTF-8');


    Windows:
    setlocale(LC_ALL, 'nld_nld');


    Linux:
    setlocale(LC_ALL, 'nl_NL');


    Of course you have to change the nl_NL to your preferred language (fr_FR, de_DE pl_PL and so on). This is tested om MODx revo 2.1.5, but I guess it will also work for newer and older versions.

    If this don't work, then you have to create a snippet [[!setlocale]] and put in this:

    setlocale(LC_ALL,'nl_NL.UTF-8');

    And call this snippet in front of your <!DOCTYPE or <html> call

    I would like to share this with you, to speed up MODx development for you all smiley


    Tags: textual representation php text strtotime strftime time datum maand taal talen months dag dagen week weekday days monday maandag januari january english german nederland french
    [ed. note: michelle84 last edited this post 11 years, 4 months ago.]
      • 37706
      • 4 Posts
      Bedankt Michelle!
      You are realy life saver. Works like charm.

      Btw. you mean config.core.php not core.config.php. :]
        • 1761
        • 20 Posts
        Super bedankt! Heb me rot gezocht...

        Btw... I added this to config.inc.php ?
          • 19328
          • 433 Posts
          Ah, yes put it in core/config/config.inc.php would also do the trick. I did put it in [webroot]/config.core.php.

          Good to hear it works! [ed. note: michelle84 last edited this post 12 years, 4 months ago.]
            • 19328
            • 433 Posts
            Now, in MODX 2.2.4 you can use the locale setting in the system settings.
            Use for dutch: nl_NL when using a linux server (not only nl)

            If this don't work (which happened to me with a 2.2.5 install on a FreeBSD 7 server), then you have to create a snippet [[!setlocale]] and put in this:

            setlocale(LC_ALL,'nl_NL.UTF-8');

            And call this snippet in front of your <!DOCTYPE or <html> call [ed. note: michelle84 last edited this post 11 years, 4 months ago.]
              • 30303
              • 25 Posts
              This is a snippet that can be used to convert English date format to any other language. This code is for Croatian language but it can be easily change to any language... just change the months and days names to any language you need.

              //SetLocalDate
              //Converts date format
              //Use: [[SetLocalDate? &date=`[[*publishedon]]`]]
               
                  
               
                 // months on Croatian language
                  $months = array(1 => "Sijecanj",    //January
                                   2 => "Veljaca", //February
                                   3 => "Ozujak",      //March
                                   4 => "Travanj", //April
                                   5 => "Svibanj", //May
                                   6 => "Lipanj",         //Jun
                                   7 => "Srpanj",      //July
                                   8 => "Kolovoz", //August
                                   9 => "Rujan",       //September
                                   10=> "Listopad",    //October
                                   11=> "Studeni", //November
                                   12=> "Prosinac");      //December
               
              $mj = date("n", strtotime($date));
               
               
              // days on Croatian language
                     $days = array(1 => "Ponedjeljak", // Monday
                           2 => "Utorak",      //Thuesday
                           3 => "Srijeda",     //Wensday
                           4 => "Četvrtak",    //Thursday
                           5 => "Petak",        // Friday
                           6 => "Subota",       //Saturday
                           7 => "Nedjelja");   //Sunday
               
              $dy = date("N", strtotime($date));
               
              //Get vars
               
              $fullday = $days[$dy]; // For example Monday
               
              $month = $months[$mj]; // For example January
               
              $day = date("d", strtotime($date)); //For example 28
               
              $year = date("Y", strtotime($date));// For example 2012
               
               
              //display date format for example:
              //Ponedjeljak, 24. Prosinac 2012.
               
              return $fullday.', '.$day.'. '.$month.' '.$year.'.';
              
              
                If we can really understand the problem, the answer will come out of it, because the answer is not separate from the problem.
                J Krishnamurti
              • @tomek

                Thank you so much for this! You saved my day...
                  MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
                  DESIGNfromWITHIN, MPThemes and Any Screen Size
                  Follow me on Twitter | Read my blog | My code on GitHub
                • Here is my French version:
                  <?php
                  //SetLocalDateFR
                  //Converts date format
                  //Use: [[SetLocalDateFR? &date=`[[*publishedon]]`]]
                  
                  // months on French language
                  $months = array(1 => "janvier",    //January
                                  2 => "février", //February
                                  3 => "mars",      //March
                                  4 => "avril", //April
                                  5 => "mai", //May
                                  6 => "juin",         //Jun
                                  7 => "juillet",      //July
                                  8 => "août", //August
                                  9 => "septembre",       //September
                                  10=> "octobre",    //October
                                  11=> "novembre", //November
                                  12=> "décembre");      //December
                    
                  $mj = date("n", strtotime($date));
                    
                  // days on French language
                  $days = array(1 => "lundi", // Monday
                              2 => "mardi",      //Thuesday
                              3 => "mercredi",     //Wensday
                              4 => "jeudi",    //Thursday
                              5 => "vendredi",        // Friday
                              6 => "samedi",       //Saturday
                              7 => "dimanche");   //Sunday
                    
                  $dy = date("N", strtotime($date));
                    
                  //Get vars
                  $fullday = $days[$dy]; // For example Monday
                  $month = $months[$mj]; // For example January
                  $day = date("d", strtotime($date)); //For example 28
                  $year = date("Y", strtotime($date));// For example 2012
                    
                  //display date format for example:
                  //Ponedjeljak, 24. Prosinac 2012.
                  
                  return $day.' '.$month.' '.$year;
                  


                  German version:
                  <?php
                  //SetLocalDateDE
                  //Converts date format
                  //Use: [[SetLocalDateDE? &date=`[[*publishedon]]`]]
                  
                  // months on German language
                  $months = array(1 => "Januar",    //January
                                  2 => "Februar", //February
                                  3 => "März",      //March
                                  4 => "April", //April
                                  5 => "Mai", //May
                                  6 => "Juni",         //Jun
                                  7 => "Juli",      //July
                                  8 => "August", //August
                                  9 => "September",       //September
                                  10=> "Oktober",    //October
                                  11=> "November", //November
                                  12=> "Dezember");      //December
                    
                  $mj = date("n", strtotime($date));
                    
                  // days on German language
                  $days = array(1 => "Montag", // Monday
                              2 => "Dienstag",      //Thuesday
                              3 => "Mittwoch",     //Wensday
                              4 => "Donnerstag",    //Thursday
                              5 => "Freitag",        // Friday
                              6 => "Samstag",       //Saturday
                              7 => "Sonntag");   //Sunday
                    
                  $dy = date("N", strtotime($date));
                    
                  //Get vars
                  $fullday = $days[$dy]; // For example Monday
                  $month = $months[$mj]; // For example January
                  $day = date("d", strtotime($date)); //For example 28
                  $year = date("Y", strtotime($date));// For example 2012
                    
                  //display date format for example:
                  //Ponedjeljak, 24. Prosinac 2012.
                  
                  return $day.'. '.$month.' '.$year;
                  


                  How I use this call:
                  [[*context_key:is=`fr`:then=`
                      [[SetLocalDateFR? &date=`[[+publishedon:strtotime:date=`%d %B %Y`]]`]]
                  `]]
                  [[*context_key:is=`de`:then=`
                      [[SetLocalDateDE? &date=`[[+publishedon:strtotime:date=`%e. %B %Y`]]`]]
                  `]]
                  [[*context_key:is=`web`:then=`
                      [[+publishedon:strtotime:date=`%d %B %Y`]]
                  `]]
                  
                    MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
                    DESIGNfromWITHIN, MPThemes and Any Screen Size
                    Follow me on Twitter | Read my blog | My code on GitHub
                    • 44375
                    • 92 Posts
                    Huge thanks for this technique. I decided to go for tomek's as I'm not sure whether the locale setting would be for all users, and as the site I'm building is multilingual I can't have one website visitor changing the locale for another. My uncertainty is because as far as I'm aware locale is a php-wide setting but I'd appreciate correction.

                    I wanted to centralize my date snippet rather than have one per language, so I used a language parameter and switch statement. I have another snippet which returns a string determining the current page's language (Eng or Esp, by looking up the article hierarchy - contexts were too complex and fine grained for my use case so I achieved the same just by having two document hierarchies and a template variable linking articles of different languages).

                    My date conversion snippet (the server locale is UK so I only need convert to Espanol):

                    <?php
                    //SetLocalDate
                    //Converts date format
                    //Use: [[snTranslateDate? &date=`[[*publishedon]]` &language=`[[snLanguageAbbrev]]`]]
                      
                    if ($language === 'Esp') {
                      
                        // months on Spanish language
                        $months = array(1 => "Enero",    //January
                                         2 => "Febrero", //February
                                         3 => "Marzo",      //March
                                         4 => "Abril", //April
                                         5 => "Mayo", //May
                                         6 => "Junio",         //Jun
                                         7 => "Julio",      //July
                                         8 => "Agosto", //August
                                         9 => "Septiembre",       //September
                                         10=> "Octubre",    //October
                                         11=> "Noviembre", //November
                                         12=> "Diciembre");      //December
                      
                        $mj = date("n", strtotime($date));
                      
                        $month = $months[$mj]; // For example 1
                      
                        $day = date("d", strtotime($date)); //For example 28
                      
                        $year = date("Y", strtotime($date));// For example 2012
                      
                        //display date format for example:
                        //Septiembre 28, 2013
                      
                        return $month.' '.$day.', '.$year;
                    
                    } else {
                        return strftime('%B %d, %Y', strtotime($date));
                    }
                    


                    My language snippet (it would be nicer if the ID wasn't hardcoded) - the code traverses up the tree to the second level in the hierarchy, irrelevant of how deep the current article is. Article 30 is the container resource for the Spanish language resources:

                    <?php
                    $id = $modx->resource->get('id'); 
                    $parentids = $modx->getParentIds($id);
                    $levelcount = count($parentids);
                    // doc id 30 = Esp container document
                    if ($parentids[($levelcount - 2)] === 30) {
                        return "Esp";
                    } else {
                        return "Eng";
                    };
                    


                    The snippet call (a latest posts template for the Articles extra, hence using + instead of * for the variable):

                    [[+publishedon:notempty=`[[snTranslateDate? &date=`[[+publishedon]]` &language=`[[snLanguageAbbrev]]`]]`]]



                    Always nice to see different approaches so thought I'd post in case it fuels someone else's creativity in some way, as the above did me, big thanks.
                    • A locale setting in a script will only apply to the running of that script. So if you call index.php by requesting a page and the locale gets set during processing, it won't have any effect on my calling of index.php when requesting a page.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org