International dates

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
plank

International dates

Post by plank »

Is there any way to change the language of the date-display in the News module?
I've got my CMS installed on a webserver in the US, but I need the dates to be in swedish.

The coolest way would probably be to somehow make a user defined tag like {locale_sv} that you could put in a template to make the date display in the right language.
Then you could put other locale-tags on other pages to make a 'sort-of' multi-language site.

Or maybe not. :)
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

International dates

Post by Ted »

{cms_module module='news' dateformat='Y.m.d'}

Date format is based on the php date function.
plank

International dates

Post by plank »

Thanks for the quick reply.

Yes, I tried manipulating the date-format a bit and I guess it would work to just use numbers instead of month names in the date.

But ideally I'd like to have the right names for days and months in the date. Like Monday 10 July would become MÃ¥ndag 10 Juli on a swedish page.

I tried sneaking in a setlocale() in one of the news-module scripts but that didn't work. Admittedly I didn't really know what i was doing.

Hmm, perhaps I could change it with som Smarty-stuff...
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

International dates

Post by Ted »

I'm sure there is a way to do it pretty easily... I've just never messed with it before. locale is one thing I've been lucky enough to stay away from with php.
plank

International dates

Post by plank »

Ah, I figured it out.
The problem is that .date doesn't respond to setlocale. So I changed it to .strftime (and adjusted the format string) in the news-script.

And after that it was easy to add a setlocale(lc_time, sv_SE); in a tag to the top of the news-page and presto, swedish names!

Hopefully I didn't break something else by doing that. :)
Krol

Re: International dates

Post by Krol »

@plank:

Could you please tell me the lines you had to edit?

- Krol
matt

Re: International dates

Post by matt »

Look for ".date" (without quotation marks) in News.module.php and replace it with ".strftime". There should be two of them.

Then set locale somewhere in the same file. I added:

Code: Select all

if (isset($params["locale"]))
{
   setlocale(LC_ALL, $params["locale"] );
}
in line 298 (after all other parameters are checked).
I can now set the locale with this additional parameter when using the news module in my templates. You can use LC_TIME instead of LC_ALL.

By the way: that's a mess. I had to set the locale to "plk" to get the polish locale on Windows and to "pl_PL" to get it to work on *nix. Why do they always have to do everything their own way at MS?
saltydog
Power Poster
Power Poster
Posts: 281
Joined: Fri Mar 04, 2005 9:06 am

Re: International dates

Post by saltydog »

matt wrote: Look for ".date" (without quotation marks) in News.module.php and replace it with ".strftime". There should be two of them.


Can't find those lines ( .date ) into the module!
Locked

Return to “CMSMS Core”