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

    I am having trouble changing the names of the months to danish. When a piece of news is posted, I want the danish date. For instance, "October" needs to be "Oktober".

    I have tried changing the locale to "da", but this have no effect. What else can I do?

    Thankyou in advance.
      • 21496
      • 225 Posts
      Make sure the locale for Danish is installed on your server. You can test this by using a command like that in a php document:

      setlocale(LC_TIME, "da_DK.UTF-8");
      echo strftime("%A, %d. %B %Y");
        René
        • 28451
        • 46 Posts
        On my local machine, it has no effect, but when I upload the php file to my server, it changes to danish. So it turns out that I have no problems - thankyou very much!
          • 28451
          • 46 Posts
          I’ll have to ressurrect this one.

          I moved my site online, and it’s still in english. But I tested it, and the danish locale is installed on the server. How do I tell modX this?

          Thanks.
            • 21496
            • 225 Posts
            What are you using for posting news? Ditto?
              René
              • 28451
              • 46 Posts
              Yes.

              In the ditto call, I use this: &dateFormat=`%d. %B %Y`

              In the chunk, I use this tag: [+date+]

              Can I change the locale in the dateFormat? I couldn’t find any mention of it in the references I found.
                • 21496
                • 225 Posts
                Quote from: Steffen.Larsen at Nov 08, 2007, 06:30 AM

                Yes.

                In the ditto call, I use this: &dateFormat=`%d. %B %Y`

                In the chunk, I use this tag: [+date+]

                Can I change the locale in the dateFormat? I couldn’t find any mention of it in the references I found.

                I think I found a solution: in the snippets folder look for /ditto/classes/ditto.class.inc.php

                Then look for "function formatDate" (line 922):

                function formatDate($dateUnixTime, $dateFormat) {
                		global $modx;
                		$dt =  strftime($dateFormat, (intval($dateUnixTime) + $modx->config["server_offset_time"]));
                		if ($modx->config["modx_charset"] == "UTF-8") {
                			$dt = utf8_encode($dt);
                		}
                		return $dt;
                	}
                


                now insert "setlocale(LC_TIME, "da_DK.UTF8");" after "global $modx", so it looks like that:

                function formatDate($dateUnixTime, $dateFormat) {
                		global $modx;
                		setlocale(LC_ALL, "da_DK.UTF8");
                		$dt =  strftime($dateFormat, (intval($dateUnixTime) + $modx->config["server_offset_time"]));
                		if ($modx->config["modx_charset"] == "UTF-8") {
                			$dt = utf8_encode($dt);
                		}
                		return $dt;
                	}
                


                I wish we could setlocale somewhere as a global setting in MODx, or maybe on the level of snippets or plugins configuration, in case we have multilanguage sites. Because by hacking the ditto files directly, you have to keep track of those changes in case you’re updating ditto.
                  René
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Couldn’t it be added to the config.inc.php file?
                    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
                    • 21496
                    • 225 Posts
                    You’re right, Susan. I first inserted it there without luck, because my string was wrong. When I finally got it working I had it in the function, and I did not check back in the config file.
                      René
                      • 28451
                      • 46 Posts
                      That’s perfect, now it works. Thankyou very much!

                      It seems like it should be a feature in the settings, though. wink