johnxx
November 5, 2019, 12:15pm
1
Hi
In the past I had many problems with dates that were not translated, despite the definition of local keys (setlocale), as also reported by several people
I’m developing ‘xDateTrans’, a MODX extra including a modifier in order to force display dates in the right language (https://forums.modx.com/thread/71553/how-to-change-date-notation-to-other-local-language ).
Documentation here : https://www.itchiweb.com/en/doc/xdatetrans.html
Ideas are wecome !
3 Likes
nuan88
November 5, 2019, 9:20pm
2
Pretty cool, thanks for this! That can save people a lot of time!
Having just had to implement this myself, thought I’d add my “solution”.
I was specifically working with the date for Blogs and wanted to use the Output Modifier, so for that, my solution is:
Add Context Setting: context_date_format and add your locale, eg de_DE.UTF-8, es_ES, it_IT etc. for each context you want.
SNIPPET: dateLocale
$value = $modx->context->getOption(‘context_date_format’, null, ‘default’);
setlocale(LC_TIME, $value);
return strftime($options,$input);
Usage
Use as Output modifier like this:
[[+publishedon:dateLocale=%e %B, %Y
]] (in feed)
[[*publishedon:dateLocale=%e %B, %Y
]] (on page)
Hat tip to Henk for inspiration: Inspiration.