HTTP_ACCEPT_LANGUAGE and setfwLocale

We are trying to use HTTP_ACCEPT_LANGUAGE to set the default locale
for a user. Is there a better way to do this?

We can see in the example how to manually set the language, but we
want to automatically set the locale based on the browser. Is this
possible?

Yes, possible.

It more depends on your business logic.

You can decide based on users browsers language capabilities (HTTP_ACCEPT_LANGUAGE), location which is detected by users IP etc. and in some cases you may want to make the default locale based on users real location such as country etc.

Sincerely,

Oğuz Demirkapı

Understood. Just wanted to know if there was a built in detection
function I was missing in the docs. Thank you!

There is no need for any custom function etc. Just parse the CGI parameter and use it as you need.

It would be nice to check the existence of the parameter because you can not rely on any CGI variables or it may have different results based on different OS/browser.

I also would suggest to set a predefined locales that your system supports and matching the locale on browser to this list and if not using the default locale.

You can test easily via Firefox locale switcher addon.
https://addons.mozilla.org/en-US/firefox/addon/1333/

Sincerely,

Oğuz Demirkapı

Yes, we are try/catch to setFWLocale and on failure it is setting to
the default.

JosephS <joseph.swenson@gmail.com>:

Yes, we are try/catch to setFWLocale and on failure it is setting to
the default.

if you wanted to get fancy you'd also look at the "q" values if there are more than 1 acceptable language listed:

en-ca,en;q=0.8,fr-ca;q=0.5,fr;q=0.3

the larger the q value the "more" acceptable the language/locale is.