We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29055
    • 7 Posts
    Hi,
    I’d like to have dates in Reflect snippet set in the language of my country. I know how to do it in PHP, but I’m new to MODX and can’t figure out how to do it in this particular case. Can you help me?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I would create a plugin using the OnWebPageInit event, then it would be available to the whole site. http://www.sottwell.com/how-plugins-work.html
        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
        • 29055
        • 7 Posts
        Ok, is plugin’s code the same to "normal" PHP?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          For your purposes, yes. Plugins are PHP code to modify the behavior of MODx without hacking the MODx core code files.
            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
            • 29055
            • 7 Posts
            Ok, I created a plugin but that doesn’t seem to work. Tried using
            setlocale(LC_TIME, "pl_PL");

            But all the dates, even that echo’ed directly from the plugin, are in English.

            Tried several other ways around, but I can’t figure out how to do it. Can you help?
              • 16702 ☆ A M B ☆
              • 536 Posts
              i thing best practice is PHx:

              1. make snippet with name phx:date_lang:

              <?php
              /*
               * description: output date with language settings
               * example: [+string:date_lang=`format`+]
               */
              $format = (strlen ( $options ) > 0) ? $options : '%a, %d %B %Y';
              setlocale ( LC_TIME, 'bg_BG.UTF-8' );
              $date_bg = strftime ( $format, 0 + $output );
              return $date_lang;
              ?>
              



              this line is your line:
              setlocale ( LC_TIME, 'bg_BG.UTF-8' );
              


              put your language and everything is fine.

              How use? For example:
              [+comment.createdon:date_lang=`%a, %d %B %Y`+]
              
                palma non sine pulvere
                • 24393
                • 83 Posts
                would a plugin like this work with YAMS?
                  stevesunderland.com
                  GRAPHICS | INTERACTIVE | MARKETING
                  xhtml + ajax + seo websites powered by modx