-
- 5 Posts
Hello MODX community.
I'm having troubles with strtotime output and locales.
I have 2 contexts on my site for use with babel.
web:
cultureKey - en
locale - en_US.utf8
ru:
cultureKey - ru
locale - ru_RU.utf8
The problem is that strtotime always use english locale for dates output. Tests that I made:
web locale en_US.utf8, ru locale = ru_RU.utf8, system locale en_US.utf8 - all dates in english
web locale en_US.utf8, ru locale = ru_RU.utf8, system locale empty - all dates in english
web locale empty, ru locale = ru_RU.utf8, system locale empty - all dates in english
web locale empty, ru locale empty, system locale ru_RU.utf8 - all dates in russian
web locale ru_RU.utf8, ru locale empty, system locale empty - all dates in russian
Looks like strtotime always uses default context's locale. Any ideas?
-
- 24,544 Posts
Do you have a 'locale' Context Setting for each Context? If not, MODX will always use the System Setting.
-
- 24,544 Posts
PHP is to blame here (MODX's strtotime modifier just calls PHP's strtotime).
See this:
http://www.php.net/manual/en/function.strtotime.php#100144
You could write a custom modifier to control the format sent to the strtotime modifier based on the locale.
-
- 5 Posts
it's not the strtotime error, imho. something wrong with modx setlocale call.
adding [[++locale]] to the template showing correct locale on each page, but the date format are always taken from "web" context or the "system settings" if "web" is empty, setting in the "ru" context is always ignored.
since I'm trying to make multilingual website, showing month names in english on the russian part of site is not a good idea.
-
- 24,544 Posts
My answer about strtotime() makes no sense. I meant strftime(), since strtotime() returns a unix timestamp.
Possibly your problem is that you're using the date output modifier, which doesn't respect the locale setting. Instead, you need to use the strftime modifier, which does. Note that the format string may be different for strftime().
http://www.php.net/manual/en/function.strftime.php
-
- 5 Posts
here is my call [[*releaseDate:strtotime:date=`%e %b %Y`]]
how to use strftime modifier here?
-
- 24,544 Posts
A snippet will be faster anyway, but this might have worked:
[[*releaseDate:strtotime:strftime=`%a %b %Y`]]
It depends on what comes back from releaseDate.