Localization of GWT app built with UiBinder doesn't work in hosted mode

痞子三分冷 提交于 2019-12-23 12:59:28

问题


Does localization of GWT app built with UiBinder work in hosted mode ? It does not for me. Here is what I did:

1) Added locale properties to GWT module's XML

< inherits name="com.google.gwt.i18n.I18N" / >
< extend-property name='locale' values='en'/>
< extend-property name='locale' values='ru'/>
< set-property-fallback name="locale" value="en"/>

2) Taged messages in *.ui.xml files with , as

< ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
     ui:generateFormat="com.google.gwt.i18n.rebind.format.PropertiesFormat"
     ui:generateKeys="com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator"
     ui:generateLocales="default"
     xmlns:g="urn:import:com.google.gwt.user.client.ui">

  < g:HTMLPanel>
     < ui:msg description="Hello Description">Hello!< /ui:msg>  
  < /g:HTMLPanel>
< /ui:UiBinder>

3) Added GWT compiler option -extra

4) Compiled the project. Found files with suffix .GenMessages.properties in the extra folder.

5) Localized generated messages. Copied each .GenMessages.properties file to the same folder with corresponding .ui.xml file. Renamed it with my locale in the file name, e.g. .GenMessages_en.properties .GenMessages_ru.properties

6) Re-compiled the project.

7) Launched the app and change locale variable in the URL for checking, e.g http://127.0.0.1:8888/TestLocale.html?gwt.codesvr=127.0.0.1:9997&locale=ru

It still shows me default English version of resources.

What am I missing ? How can I even debug it ? There is nothing in logs or output.

I'm under Windows, using IntelliJ IDEA and Chrome as browser.

Thanks!

Update: It didn't work because I had extra < set-property name="locale" value="en"/ > in module config :( Perhaps it was overriding values from extend-property tag.

I wrote step-by-step description how to make it work here in case somebody is interested.


回答1:


By default GWT generates properties files which start with package name. Did you remove package from file name?

One thing that worked best for me in my GWT projects is using LocalizableResource_.properties as file names and keeping them all in com/google/gwt/i18n/client package. Check out GWT documentation on Localization with UiBinder




回答2:


The .properties file doesn't have to be under the client package. The key is to make sure that wherever you decide to store your properties file, make sure that the package it's located in is also in your module's path. On my projects, I normally put the properties files under a res package:

com/project/gwt
com/project/gwt/client
com/project/gwt/res
com/project/gwt/res/strings

Then the main interface, along with all the individual properties file for each language go under strings. This works fine as long as your module.xml file includes the line

<source path="res" />


来源:https://stackoverflow.com/questions/8064371/localization-of-gwt-app-built-with-uibinder-doesnt-work-in-hosted-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!