GWT I18N 属性"区域设置"的 JavaScript 问题



我在加载GWT项目时遇到以下错误(在尝试使区域设置正常工作时…(:

Error while executing the JavaScript provider for property 'locale'
com.google.gwt.core.client.JavaScriptException: (TypeError) __gwt_getProperty([string: 'locale']): undefined is not a function
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)

我遵循了以下指示:

模块文件中的第一个:

<inherits name="com.google.gwt.i18n.I18N"/>
<extend-property name="locale" values="en" />
<extend-property name="locale" values="zh" />
<set-property-fallback name="locale" value="en" />
<set-configuration-property name="locale.useragent" value="Y" />

还创建了一个基本的常量类,如下所示:

import com.google.gwt.i18n.client.Constants;
public interface LocaleConstants extends Constants {
    @Key("locale.name")
    String localeName();
    @Key("locale.code")
    String localeCode();
    @DefaultStringValue("Hello")
    String hello();
[...]

具有相应的属性文件,如"LocaleConstants_en.properties":

locale.name=English
locale.code=en
hello=Hi

我从头开始尝试了一个新项目,效果很好。我不知道是什么导致了我现有项目的问题。

有线索吗?谢谢

确保在您的主机页(在<head>中(中设置了区域设置:

<meta name="gwt:property" content="locale=en">

我遇到了与您类似的问题。

或者,您可以将元标签写为

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

绕过这个问题。

然而,当前的HTML5元标记格式<meta charset="UTF-8">将导致另一个错误,因为com.google.gwt.core.client.JavaScriptException: (TypeError) __gwt_getProperty([string: 'locale']): j[a] is not a function,所以请不要使用HTML5支持的字符集缩短元。

最新更新