要为 GWT 应用程序添加对语言环境的支持,您需要在 xxx.gwt.xml 中执行以下操作:
在<module>
添加此以包括支持:
<inherits name="com.google.gwt.i18n.I18N" />
这是配置它:
<extend-property name="locale" values="en,it"/>
<set-property-fallback name="locale" value="en"/>
在一些包下添加所有属性文件,如下所示:
src/main/resources/foo/bar/client/i18n/MyMessages.properties
src/main/resources/foo/bar/client/i18n/MyMessages_it.properties
然后你需要告诉 GWT 将它们编译成类。这是来自 pom.xml 文件的示例(如果您不使用 maven,则必须使用不同的方式,但仍需要对其进行配置)。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.3.1.google</version>
<executions>
<execution>
<goals>
<goal>i18n</goal>
<goal>generateAsync</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<i18nMessagesBundles>
<resourceBundle>foo.bar.client.i18n.MyMessages</resourceBundle>
</i18nMessagesBundles>
</configuration>
</plugin>
然后你需要重新编译代码。在 Mavenmvn compile
中。就是这样,您将在生成的源文件夹中准备好您的消息以供使用。