如何使用LocaleInfo获取GWT中的当前语言环境 [英] How to get the Current Locale in GWT using LocaleInfo
问题描述
我试图使用LocaleInfo类和getCurrentLocale()方法获取客户端上的当前语言环境。但是,无论客户端机器上具有哪些区域设置和语言环境设置,它总是返回值的默认语言环境。
Date类toLocaleString()方法返回一个特定于语言环境的字符串,但LocaleInfo似乎无法获取系统Locale。
GWT的语言环境不会从系统/浏览器设置中自动获取。根据 GET语言环境文档,运行时使用的语言环境可以是可以通过以下两种方式之一进行设置:
- 通过在您的
c> locale 应用程序的URL。即 http://www.myapplication.com/?locale=es
-
通过包含
< meta name =gwt:propertycontent = gwt:property
meta标签在主页中:
这是生产应用程序的首选方法。您的主机页面可以通过多种方式确定用户的区域设置,包括但不限于允许用户配置本地或基于
Accept-Language
请求标题。
I have tried to get the current locale on the client using the LocaleInfo class and the method getCurrentLocale(). However it always returns the value default locale no matter what regional and locale settings I have on the client machine.
The Date classes toLocaleString() method returns a locale specific string but the LocaleInfo doesn't seem to be able to get the systems Locale.
Locales for GWT are not automatically obtained from the system/browser settings. As per the GET locale documentation the locale to use at run time can be set in one of two ways:
- By specifying a
locale
request parameter in your application's URL. I.e.http://www.myapplication.com/?locale=es
By including a
gwt:property
meta tag in the host page:<meta name="gwt:property" content="locale=es" />
This is the preferred method for production applications. Your host page can determine the user's locale in a number of ways including, but not limited to, allowing the user to configure a local or detecting their preferred locale based on the
Accept-Language
request header.
这篇关于如何使用LocaleInfo获取GWT中的当前语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!