We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I've got an English/French site, in one section I am outputting news articles & formatting the date with an output filter like this:

    [[+publishedon:strtotime:date=`%b %e, %Y`]]


    Which works great on the English side - but how can I get it to output French Month names on the French side??

    This question has been answered by BobRay. See the first response.

      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
    • discuss.answer
      • 3749
      • 24,544 Posts
      IIRC, the PHP date() function doesn't respect the 'locale' setting, but strftime() does.

      IOW, try replacing the date modifier with the strftime modifier.

      I ranted a little about MODX date handling here: http://bobsguides.com/blog.html/2013/08/19/displaying-modx-resource-date-fields/, and there's a method for doing exactly what you want with a snippet, which should be significantly faster.
        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
        • 26503
        • 620 Posts
        Thanks again Bob;

        It mostly works, I have something like this from following your post:


        <?php
        /* DateFormat snippet */
        
        $locale = $modx->getOption('locale');
        
        setlocale(LC_ALL, $locale);
        
        $field = $scriptProperties['field'];
        
        $format = $scriptProperties['formatString'];
        
        $resource = $modx->getObject('modResource', $scriptProperties['id']);
         
        $timestamp = $resource->_fields[$field];
        
        return strftime($format, $timestamp);




        I could not get the script to recognize the 'locale' setting in the French context, I had to grab it in the snippet like above.

        Now while this works, it appears to output all the French months as lowercase [janv, juil, mars, etc] AND also output funny characters in other months:

        "ao�t 2, 2012 & f�vr. 19, 2013"


        even though I'm using a utf-8 character set & 'fr' content language meta...

        <meta name="content-language" content="fr" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


        Any ideas what may be causing that?



          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525
          • 26503
          • 620 Posts
          A little update, I had to add a little to the script to get it to output in the correct character set, I have no idea how or where it got the weird windows formatting...

          <?php
          /* DateFormat snippet */
          
          $locale = $modx->getOption('locale');
          
          setlocale(LC_ALL, $locale);
          
          $field = $scriptProperties['field'];
          
          $format = $scriptProperties['formatString'];
          
          $resource = $modx->getObject('modResource', $scriptProperties['id']);
           
          $timestamp = $resource->_fields[$field];
          
          $date_formatted = strftime($format, $timestamp);
          
          return iconv('Windows-1252','UTF-8',$date_formatted);
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Probably got the Windows charset from the server. I've had to convert like that for uploaded filenames on a Windows server.
              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