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.

General Questions /

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

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

Language fallback mechanism


Reply


2 Posts   1197 Views

Avatar
subpixel

Community Member, 4 Posts

24 August 2010 at 7:10pm

Hi, I'm using SS 2.4.1 with multilingual site (Translatable extension).
I would like to know if there's any client language recognition? If so, how is it working?
I've set default language to different one than is my locale, and I've received page in default language (so it's not working, but I might set something wrong).
What I'm looking for is a mechanism that would try to set language to client locale language and if there isn't such translation it should fallback to default one.
Also what do you think about setting lang to $_SERVER["HTTP_ACCEPT_LANGUAGE"]. Is it safe?

Regards

Avatar
subpixel

Community Member, 4 Posts

27 August 2010 at 10:22pm

Hey,

I placed this code in page_controller init function.

if (substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)!='de') {
   Translatable::set_current_locale('en_US');
   i18n::set_locale('en_US');
} else {
...
}


However, it did it's job only partial. I got navigation from appropriate translation, but haome page and error pages came from default locale.

Than I moved this code to _config.php. And it solved all my problems.
However it seems like an ugly hack. Anyone has a better idea?

Note: I know it's a really simple condition, but I have a bilingual site and I'm not looking for anything sophisticated.