Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GWT ignore browser locale?

Tags:

browser

gwt

GWT gets locale from either the locale property or the locale query string. If neither is specified, it uses the "default" (ie en_US) locale.

Why doesn't it get it from the browser settings?

It seems the only solution to this is to replace your static html launch page with something like a JSP that reads the browser locales and sets the locale or redirects using the query string. There has to be a better solution than this or simply hard-coding a locale, surely?

like image 310
cletus Avatar asked Oct 01 '08 06:10

cletus


3 Answers

You can also put this switch in your *.gwt.xml

<set-configuration-property name="locale.useragent" value="Y"/>

this will add language selecting based on language selected in browser. You can also control search order for locale by setting

  <set-configuration-property name="locale.searchorder" value="queryparam,cookie,meta,useragent"/>

But beware that in IE this doesn't work - you should develop server-side language pick based on 'Accept-Language' header send by the IE.

like image 89
ljader Avatar answered Nov 15 '22 19:11

ljader


If you put a list of available languages into your *.gwt.xml file it will by default switch to the first language listed.

<!-- Slovenian in Slovenia -->
<extend-property name="locale" values="sl"/>

<!-- English language, independent of country -->
<extend-property name="locale" values="en"/>
like image 38
Drejc Avatar answered Nov 15 '22 18:11

Drejc


You can use a cookie to save and send this value, but for that you have to add in your *.gwt.xml first

<set-configuration-property name="locale.cookie" value="yourCookieName"/>
<set-configuration-property name="locale.searchorder" value="queryparam,cookie,meta,useragent"/>

Note that "queryparam" has the biggest priority here, that allows to set a new locale using the http query and ignore the value on the cookie.

like image 1
Jorge P. Avatar answered Nov 15 '22 19:11

Jorge P.