6

GWT从语言环境属性或语言环境查询字符串获取语言环境。如果两者都没有指定,它使用“默认”(即en_US)语言环境。

为什么它不能从浏览器设置中获取?

似乎唯一的解决方案是将静态 html 启动页面替换为 JSP 之类的东西,该 JSP 读取浏览器区域设置并使用查询字符串设置区域设置或重定向。肯定有比这更好的解决方案,或者只是对语言环境进行硬编码,当然?

4

6 回答 6

6

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.

于 2011-11-03T09:19:44.500 回答
3

如果您将可用语言列表放入 *.gwt.xml 文件,默认情况下它将切换到列出的第一种语言。

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

<!-- English language, independent of country -->
<extend-property name="locale" values="en"/>
于 2008-10-02T08:14:32.707 回答
1

您可以使用 cookie 来保存和发送此值,但为此您必须先添加* .gwt.xml

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

请注意,“ queryparam”在这里具有最大的优先级,它允许使用http查询设置新的语言环境并忽略 cookie 上的值。

于 2013-05-18T18:30:55.050 回答
0

在您的*.gwt.xml文件中添加此条目以查看效果!

请检查以下行以获取更多信息!

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

于 2013-06-25T11:48:45.343 回答
0

如果您的入口页面是 JSP,您可以检查请求的Accept-Language标头以动态设置语言环境。

于 2011-11-24T16:00:42.637 回答
0

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
于 2015-02-10T15:21:11.187 回答