Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Trouble with Translatable and _t()?


Go to End


3 Posts   1579 Views

Avatar
omarkohl

Community Member, 30 Posts

26 December 2010 at 6:47am

If you have a site in several languages and you want to save yourself a lot of trouble and a few hours of headache I recommend you put this in the init() function of your Page_Controller.

i18n::set_locale(Translatable::get_current_locale());
setlocale(LC_ALL, i18n::get_locale());

Otherwise string translated using _t() or php functions like strftime won't work as you want them to.

I can see the point SilverStripe developers tried to make when separating i18n from Translatable and in theory it makes sense. In practice though its really annoying because _t() is used so much in SS modules.

Avatar
dacar

Community Member, 173 Posts

9 February 2011 at 2:42am

Omarkohl, you are a the best. I have played with this for hours without success. Just insert the code and everything was fine. This shut be put to the documentation!

Avatar
ordinarywebguy

Community Member, 13 Posts

9 February 2011 at 3:37am

Try putting it up this like:

setlocale(LC_TIME, i18n::get_locale() . '.utf8');

It should do the trick.