We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23050
    • 1,842 Posts
    Hi,

    I would like to display date in french. I add

    setlocale (LC_ALL, 'fr_FR.utf-8');


    at the top of the code, but the month remains in english.

    Any idea or solution to correct that ?

    Thanks wink
      • 36592
      • 970 Posts
      How are you specifying &format parameter ?
        • 23050
        • 1,842 Posts
        The format is in the snippet code :

        $format="<span class='jour'>%d</span> <span class='mois'>%b</span>";
          • 36592
          • 970 Posts
          I inserted these two lines at the top of the DateTime snippet.
          setlocale (LC_ALL, 'fr_FR.utf-8');
          $format="<span class='jour'>%d</span> <span class='mois'>%b</span>";
          

          and the output is "<span class=’jour’>17</span> <span class=’mois’>déc</span>".
          It looks like it’s working correctly in my environment.
            • 23050
            • 1,842 Posts
            Ah ! Well, I may have a look to the setlocale so and see why it doesn’t work on my server. Thank you for your tests smiley
              • 33014 ☆ A M B ☆
              • 1,231 Posts
              <?php
              if(isset($type))    $src    = $type;
              if(!isset($src))    $src    = 'createdon';
              if(!isset($format)) $format = $modx->toDateFormat(null, 'formatOnly') . ' %H:%M:%S';
              if(!isset($shift))  $shift  = 0;
              
              $a = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
              $A = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
              
              switch($src)
              {
              	case 'createdon'  :
              	case 'publishedon':
              	case 'editedon'   :
              	case 'pub_date'   :
              	case 'unpub_date' :
              	case 'deletedon'  :
              		$timestamp = $modx->documentObject[$src];
              		break;
              	default:
              		$timestamp = $modx->documentObject[$src][1];
              		$timestamp = strtotime($timestamp);
              }
              
              $peaces    = preg_split('@(%[\-#]?[a-zA-Z%])@',$format,-1,2);
              $timestamp = $timestamp + $shift + $modx->config['server_offset_time'];
              $w         = strftime('%w', $timestamp);
              $result    = '';
              foreach($peaces as $v)
              {
                if    ($v == '%a') $result .= $a[$w];
                elseif($v == '%A') $result .= $A[$w];
                elseif(strpos($v, '%')!==false) $result .= strftime($v, $timestamp);
                else $result .= $v;
              }
              return $result;
              ?>


              Locale free
              and
              Encode garble free

              $a = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
              $A = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

              Need ajust, each country.
                • 4310
                • 2,310 Posts
                Thanks yama.
                Congratulations on reaching 1000 posts smiley
                  • 33014 ☆ A M B ☆
                  • 1,231 Posts