Search code examples
javagwtlocalizationintellij-ideauibinder

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


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.


Solution

  • 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