We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    FYI: date() doesn't respect the locale setting -- strftime() does. Using strftime() will give you the language-appropriate month and day names.

    You can always call setlocale() just before calling strftime().
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 44307
      • 7 Posts
      And for good measure, here's a Lithuanian version:
      <?php
      //setDateLT
      //Converts date format
      //Use: [[setDateLT? &date=`[[*publishedon]]`]]
       
      // months in Lithuanian
      $months = array(1 => "sausio",		//January
                      2 => "vasario",		//February
                      3 => "kovo",		//March
                      4 => "balandžio",	//April
                      5 => "gegužės",		//May
                      6 => "birželio",	//Jun
                      7 => "liepos",		//July
                      8 => "rugpjūčio",	//August
                      9 => "rugsėjo",		//September
                      10=> "spalio",		//October
                      11=> "lapkričio",	//November
                      12=> "gruodžio");	//December
         
      $mj = date("n", strtotime($date));
         
      // days in Lithuanian
      $days = array(1 => "pirmadienis", // Monday
                  2 => "antradienis",      //Thuesday
                  3 => "trečiadienis",     //Wensday
                  4 => "ketvirtadienis",    //Thursday
                  5 => "penktadienis",        // Friday
                  6 => "šeštadienis",       //Saturday
                  7 => "sekmadienis");   //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 example:
      //2014 m. kovo 11 d.
       
      return $year.' m. '.$month.' '.$day.' d. ';
        • 30303
        • 25 Posts
        Quote from: BobRay at Sep 30, 2013, 09:34 AM
        FYI: date() doesn't respect the locale setting -- strftime() does. Using strftime() will give you the language-appropriate month and day names.

        You can always call setlocale() just before calling strftime().



        “When you know better you do better.” smiley
        P.S. Thanks for tip.
          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
        • Magnatron [Maarten Wolzak] Reply #14, 9 years, 9 months ago
          If you find the system setting "Locale" dosn't work for you, you might want to try to add the character encoding to it.

          Setting the system setting to
          nl_NL
          did not work for a recent project (LEMP) but
          nl_NL.UTF-8
          did the trick
            • 40169
            • 16 Posts
            @tomek Thank you very much for this snipet. It is great solution for any language.

            "Puno ti hvala, ovo je super stvar."
              • 48571
              • 2 Posts
              Why not using the lexicon?

              <?php
              //langDate
              //Converts date format
              //Use: [[langDate? &date=`[[*publishedon]]`]]
                
              $modx->lexicon->load('core:default');
              
              $month = strtolower(date('F', strtotime($date) ));
              $day = strtolower(date('l', strtotime($date) ));
              
              
              $dy = date("N", strtotime($date));
              
              
              $fullday = $modx->lexicon($day); //Monday in current language
              
              $month = $modx->lexicon($month);//May in current language
                
              $day = date("d", strtotime($date)); // 13
              
              $year = date("Y", strtotime($date)); // 2014
                
              
              
              return $fullday.', '.$day.'. '.$month.' '.$year;
              
                • 46580
                • 167 Posts
                For me with MODX 2.3.3

                locale in system settings > doesn't work
                locale in context settings > doesn't work

                Snippet :
                <?php
                $locale = $modx->context->getOption('locale', null, 'default');
                setlocale(LC_ALL,$locale.'.UTF-8');


                works fine ([[!setlocale]] call in header)
                  MODX lover
                  -
                  Développeur MODX / Webdesign / Solutions web
                  • 38525
                  • 26 Posts
                  I encoutered similar problems, and fixed it by setting the locale through a custom gateway plugin that was being used:

                  $eventName = $modx->event->name;
                  if($modx->context->get('key') == 'mgr' || $eventName != 'OnHandleRequest') { return ''; }
                  
                  $hostname = $_SERVER['HTTP_HOST'];
                  switch($hostname) {
                      case 'mywebsite.de':
                          $modx->switchContext('deutsch');
                          setlocale(LC_ALL,$modx->context->getOption('locale', null, 'default'));
                      break;
                  }  
                  


                  I have no idea why the context setting is not being picked up in the first place, but adding this line fixed it for me..
                    • 18941
                    • 3 Posts
                    For me with MODX 2.3.5-pl

                    in "system settings > core > locale"
                    setting the value to "de_DE"

                    works fine for german language settings with strftime()
                      • 43968
                      • 25 Posts
                      Quote from: mdeuerlein at Aug 01, 2015, 07:55 PM
                      For me with MODX 2.3.5-pl

                      in "system settings > core > locale"
                      setting the value to "de_DE"

                      works fine for german language settings with strftime()

                      For me as well on version 2.5.8