thanks,
adding
setlocale(LC_TIME, i18n::get_locale() . ".utf8");
to the function FormatI18N also helped me to solve an "umlaut" - bug with "märz".
thank you,
florian
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
thanks,
adding
setlocale(LC_TIME, i18n::get_locale() . ".utf8");
to the function FormatI18N also helped me to solve an "umlaut" - bug with "märz".
thank you,
florian
I've tried all of the above on an SS2.4.2 install:
Added this in _config.php:
Translatable::set_default_locale('nl_NL');
Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');
i18n::set_locale('nl_NL');
setlocale(LC_TIME, 'nl_NL');
Altered function FormatI18N() in sapphire/core/model/fieldtypes/Date.php:
function FormatI18N($formattingString) {
setlocale(LC_TIME, i18n::get_locale() . ".utf8");
if($this->value) return strftime($formattingString, strtotime($this->value));
}
Have this in my BlogEntry.ss:
$Date.FormatI18N(%e %B)
And still I get 'October' instead of the Dutch 'oktober'. What am I doing wrong?
PS. $Locale in my Page.ss does provide me with nl_NL
PPS. It does work on my local MAMP environment. On shared hosting it doesnot work, even with this code (server issue?!):
function FormatI18N($formattingString) {
setlocale(LC_TIME, i18n::get_locale() . ".utf8");
setlocale(LC_TIME, 'nl_NL.UTF8');
if($this->value) return strftime($formattingString, strtotime($this->value));
}
As it also took me quite some time to get datefields printed in the correct locale (of the visitor), I'll outline how I achieved this (SS2.4.5);
To translate $Date fields for the current locale, first set the correct locale. This code works for me if I put it in the Page_Controller (_config.php seems to be too early):
// mysite/code/Page.php
class Page_Controller extends ContentController {
public function init() {
...
// Set locale for PHP, dates etc;
setlocale(LC_TIME, Translatable::get_current_locale() . ".UTF8");
// using i18n::get_locale() didn't seem to work for me;
// setlocale(LC_TIME, i18n::get_locale() . ".utf8");
}
}
Then cast the date to the current locale in your template;
$Date.FormatI18N(%e %B %Y)
If this is not working, make sure you add a ?flush=1 to the URL.
Still not working, it could be that the locale is not installed on the server. If you have a shell account, do a
locale -a
This shows you all installed locales. If the needed locale is indeed not installed, you can install it yourself if you have root (Debian/Ubuntu);
dpkg-reconfigure locales
And add the neede locale. It should also be possible to install locales in your home directory (as non-root), Google probably knows best...
Many thanks, I'll try this myself!
I have created a small module for SS3 that will translate dates automatically once added to your project. You can check it out here: https://github.com/richardsjoqvist/silverstripe-localdate
Bug reports and improvement suggestions are most welcome!