Why does GWT ignore browser locale?

后端 未结 6 345
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 23:30

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.

相关标签:
6条回答
  • 2021-01-02 23:57

    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.

    0 讨论(0)
  • 2021-01-03 00:00

    This worked for me, I hope it also works for you.

    My problem was that I have not declared any locale value in .gwt.xml module descriptor. In that case only the default locale is used. GWT does that way because any different supported locale means a new compilation iteration/permutation. Therefore only declared locales are used.

    Here you are an example:

    <!-- Locales -->
    <extend-property name="locale" values="en_US"/>
    <extend-property name="locale" values="es"/>    
    <set-property-fallback name="locale" value="en_US"/>
    <set-configuration-property name="locale.useragent" value="Y" />
    <set-configuration-property name="locale.searchorder" value="queryparam,cookie,meta,useragent" />
    

    The first and second lines set the available/supported locales (English from US and Spanish without specific country in my example). The third line sets the default locale in case no one is detected (this default declaration must be set after the default value is declared in a extend-property line). The fourth line enables the locale detection by means of the HTTP-Headers Accept-Language sent by browser (probably is enabled by default and not needed to set at all). The final line sets the order in which the different detection mechanisms try to detect the locale:

    1. As a parameter in the URL query
    2. From cookies
    3. As a meta value in the HTML page
    4. From the HTTP header sent by browser
    0 讨论(0)
  • 2021-01-03 00:02

    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.

    0 讨论(0)
  • 2021-01-03 00:05

    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"/>
    
    0 讨论(0)
  • 2021-01-03 00:06

    If your entry page is a JSP you can inspect the request's Accept-Language header to dynamically set the locale.

    0 讨论(0)
  • 2021-01-03 00:07

    add this entry in your *.gwt.xml file to see the effect!

    Please check the following line for more information!

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

    0 讨论(0)
提交回复
热议问题