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

Language fallback mechanism


Go to End


2 Posts   2035 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.