I'll explain how to localize your GWT application that uses UiBinder.
1) You need to modify your gwt module xml
4) Compile the project. You'll see number of
5) Copy each .properties file to the same folder with corresponding .ui.xml file.
6) Rename each .property file so it doesn't have package name e.g.
7) Translate strings in each file.
8) Recompile the project.
9) Now you can test locales but passing it in URL. For example
PS.
There are few things you may consider. Official tutorial recommends using
1) You need to modify your gwt module xml
<!--Defines all possible locales we'll use--> <extend-property name="locale" values="en,ru"/> <!--Defines default locale--> <set-property-fallback name="locale" value="en"/>2) Tag messages in *.ui.xml files with <ui:msg>, e.g.
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui' ui:generateFormat="com.google.gwt.i18n.rebind.format.PropertiesFormat" ui:generateKeys="com.google.gwt.i18n.server.keygen.MD5KeyGenerator" ui:generateLocales="en,ru"> <g:HTMLPanel> <ui:msg key="msg2" description="test description2">Test2!</ui:msg> <ui:msg key="msg1" description="test description">Test!</ui:msg> <ui:msg>Test3!</ui:msg> </g:HTMLPanel> </ui:UiBinder>3) Add GWT compiler option -extra that produces resource file with strings.
4) Compile the project. You'll see number of
"*UiBinderImplGenMessages_*.properties" in extras folder. For example com.localeTest.client.MyViewMyViewUiBinderImplGenMessages_en.properties. Each property file corresponds to UiBinder xml they were made from.5) Copy each .properties file to the same folder with corresponding .ui.xml file.
6) Rename each .property file so it doesn't have package name e.g.
MyViewMyViewUiBinderImplGenMessages_en.properties.7) Translate strings in each file.
8) Recompile the project.
9) Now you can test locales but passing it in URL. For example
http://127.0.0.1:8888/LocaleTest.html?gwt.codesvr=127.0.0.1:9997&locale=ruPS.
There are few things you may consider. Official tutorial recommends using
MD5KeyGenerator to automatically generate IDs for string. I prefer explicitly set IDs because of how different key generators work.MD5KeyGenerator- generates ID from text. If you change text ID will change too.FullyQualifiedMethodNameKeyGeneratorandMethodNameKeyGenerator- generates ID such as msg1, msg2 where number is order of a string in your file. So if you swap two strings ID will change too and you will have to catch it in other locales.

This comment has been removed by the author.
ReplyDelete