My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
MergeLocale  
Information on the mergelocales script that facilitates GWT internationalisation
Type-Documentation
Updated Jan 2, 2011 by marius.a...@gmail.com

Introduction

Using UIBinder internationalisation features can be difficult. This has been discussed extensively on GWT Issue 4355.

Solution

To overcome this problem, GWTP makes it easy for you to store all your translations in:

  • src/com/google/gwt/i18n/client/LocalizableResource.properties
  • src/com/google/gwt/i18n/client/LocalizableResource_fr.properties
  • etc.

However, it is still necessary to keep all these files synchronized with one another. In addition, you want to make sure they contain any message included in a UIBinder xml file. To do so, GWTP lets you use the python script mergelocales.py. The script can be found in the Downloads section.

The exact process is as follows:

  • Compile GWT code by adding parameter -extra extras
  • Run mergelocales extras/YourProjectName src/com/google/gwt/i18n/client/
  • Go through the LocalizableResource_xxxx.properties files and solve the TODO comments.

For more details on the script, run mergelocales --help.

Additional information

GWT looks for the LocalizableResource???.properties files in the directory of your class implementing Constants or Messages, and in the directory of any super interfaces. The problem with UiBinder translations is that the associated LocalizableResource files are generated in the folder of the UiBinder file, so your resources are spread across your directories. mergelocale looks for all of these and merge them intelligently in a central location: com.google.gwt.i18n.client. This is legit since this package is the directory of the LocalizableResource, a superinterface common to both Constants and Messages.

When compiling a localized GWT project, one has to

  1. compile 1st time, to generate extras locales
  2. run mergelocale and update translations
  3. compile 2nd time, so translations are included in the results

Comment by pfrangi...@gmail.com, Jun 30, 2010

Hi, I'm working on a GWT 2.0 project, and we use UI Binders. We'd like to internationalize everything, but we're having some troubles:

The project uses Maven 2, the projects structure looks like:

project/
-- services/
------ service1/
------ service2/
------ serviceN/
------ gwt-services/
-- ui/
------ ui1/
------ ui2/
-- web/
------ xxx/
------ webapp/

(each project has the common Maven 2 structure)

gwt-services uses the different serviceX project. ui1 and ui2 projects use gwt-services and contains the 2 different parts of our application. The webapp project uses both ui projects. The webapp project's pom.xml uses the gwt-maven-plugin. It compiles 2 modules, one per ui project. So after a build, in web/webapp/target/extra/, we have 2 directories: ui1 and ui2, which contain the different .properties files generated from the UI Binders.

If we run:

python2.5 mergelocales.py ./web/webapp/target/extra/ui1/ ./web/webapp/src/main/resources/com/google/gwt/i18n/client/

everything works fine.

But we also have to run:

python2.5 mergelocales.py ./web/webapp/target/extra/ui2/ ./web/webapp/src/main/resources/com/google/gwt/i18n/client/

which is going to overwrite the LocalizableResource?.properties generated by the first call.

The best for us would actually be to do:

python2.5 mergelocales.py ./web/webapp/target/extra/ui1/ ./ui/ui1/src/main/resources/com/google/gwt/i18n/client/

and:

python2.5 mergelocales.py ./web/webapp/target/extra/ui2/ ./ui/ui2/src/main/resources/com/google/gwt/i18n/client/

This way we would have one LocalizableResource?.properties file per ui project (and that would be perfect for us).

But when we do this, we get an error:

Processing translations in: /path-to-project-root/web/webapp/target/extra/ui1/com.xxx.yyy.zzz.View1View1BinderImplGenMessages.properties
Traceback (most recent call last):
  File "mergelocales.py", line 497, in <module>
    main()    
  File "mergelocales.py", line 131, in main
    mergeLocales( args[0], args[1] )
  File "mergelocales.py", line 466, in mergeLocales
    pathname = os.path.join( resourcesDir, defaultLocaleFilename )
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 60, in join
AttributeError: 'NoneType' object has no attribute 'startswith'

My python skills are very limited and I don't have much time to look at the script anyway, so I wanted to get your thoughts on this first?

Thank you very much, Phil

Comment by Greg.Hen...@gmail.com, Sep 20, 2010

i think your problem is defaultLocaleFilename does not exist

Comment by sam.spyc...@gmail.com, May 31, 2011

Hi

With the mergelocales.py given above, I get "# TODO: DEPRECATED (CONSIDER REMOVING)" for every property under "### NON-UIBINDER TRANSLATIONS", i.e. for those properties which should be left alone because they are Message or Constant text resources and therefore cannot be found anyway in the binder resource files.

I removed the issue (and hopefully did not create a new one) by replacing line 326 in your mergelocales.py:

if not otherCollection._map.has_key(property._key):

with the following:

if not otherCollection._map.has_key(property._key) and not property._nonUIBinder:

Hth, Sam

Comment by dpar...@gmail.com, May 1, 2012

I'm having compatibility issues with python and perhaps GWT 2.4. If I use python 3.2.3 this script executes with a syntax error:

File "D:\temp\mergelocales.py", line 117
except getopt.error, msg:
^

SyntaxError?: invalid syntax

In my current GWT 2.4 project I get this failure:

Traceback (most recent call last):

File "D:\temp\mergelocales.py", line 497, in <module>
main()
File "D:\temp\mergelocales.py", line 131, in main
mergeLocales( args0?, args1? )
File "D:\temp\mergelocales.py", line 466, in mergeLocales
pathname = os.path.join( resourcesDir, defaultLocaleFilename )
File "C:\Python27\lib\ntpath.py", line 73, in join
elif isabs(b):
File "C:\Python27\lib\ntpath.py", line 57, in isabs
s = splitdrive(s)1?
File "C:\Python27\lib\ntpath.py", line 125, in splitdrive
if p[1:2] == ':':
TypeError?: 'NoneType?' object has no attribute 'getitem'

Comment by acojoc...@visual-tools.com, May 23 (4 days ago)

for dpar...@gmail.com

Hello David,

it seems like the script is expecting no suffix for the ''default'' language .properties file, while GWT 2.4 generates the file with the suffix ''default'' (e.g., expecting ''MyMessages?.properties'' but having ''MyMessages?_default.properties'').

I managed to resolve that problem by modifying the script ''mergelocales.py'' at line 449.

Instead of:

 if locale != '':

I am using:

 if locale != 'default':

And everything works fine again.


Sign in to add a comment
Powered by Google Project Hosting