Introduction

The localize utility is a simple command-line tool created to help non-programmers to localize well-written JavaTM applications.

If a Java application is delivered using one or several .jar files and if some of these Jar files contain .properties resource files, the localize utility may be applied to the Jars. Note that Java source code is not needed, neither is a JDK (Java Development Kit).

For modularity reasons, Java applications are localized at the class (example: a dialog box class) or at the package level (example: a framework of tightly coupled classes) by creating a text file with extension .properties for each class or package to be localized.

These .properties files contain key=value pairs, where key is the identifier of a message, button label or menu item and value is the localized text.

Each language supported by the Java application must have its own .properties variant. Example: Foo.properties for the default language (generally English), Foo_fr.properties for French, Foo_es.properties for Spanish and so on.

For a mid-size Java application, one may end up with dozens of such .properties files. Without the help of the localize utility, adding support for a new language, say German, means creating dozens of *_de.properties files, which is tedious and error-prone.

Three steps are needed to localize a Java application:

  1. Using the localize utility, extract all the messages in a given language from the Jar (example: English, if English is the reference language of the application).
    ++++++++++com/xmlmind/xmleditapp/TagChooserDialogRes.properties
    
    error=Error
    error=
    
    invalidTag={0} is not a valid name
    invalidTag=
    
    ----------com/xmlmind/xmleditapp/TagChooserDialogRes.properties
    ++++++++++com/xmlmind/xmleditapp/ValidityDiagToolRes.properties
    
    close=Close
    close=
    
    title=Check validity
    title=
    
    ----------com/xmlmind/xmleditapp/ValidityDiagToolRes.properties
  2. Using a text editor, fill-in the blanks in the extracted message file by translating each message to the new language.
    ++++++++++com/xmlmind/xmleditapp/TagChooserDialogRes.properties
    
    error=Error
    error=
    
    invalidTag={0} is not a valid name
    invalidTag=
    
    ----------com/xmlmind/xmleditapp/TagChooserDialogRes.properties
    ++++++++++com/xmlmind/xmleditapp/ValidityDiagToolRes.properties
    
    close=Close
    close=
    
    title=Check validity
    title=
    
    ----------com/xmlmind/xmleditapp/ValidityDiagToolRes.properties
  3. Using a text editor, fill-in the blanks in the extracted message file by translating each message to the new language.
    ++++++++++com/xmlmind/xmleditapp/TagChooserDialogRes.properties
    
    error=Error
    error=Erreur
    
    invalidTag={0} is not a valid name
    invalidTag={0} n'est pas un nom valide.
    
    ----------com/xmlmind/xmleditapp/TagChooserDialogRes.properties
    ++++++++++com/xmlmind/xmleditapp/ValidityDiagToolRes.properties
    
    close=Close
    close=Fermer
    
    title=Check validity
    title=Vérifier validité
    
    ----------com/xmlmind/xmleditapp/ValidityDiagToolRes.properties
  4. Using the localize utility, patch the Jar with the edited message file. (The localize utility adds appropriate .properties files to the Jar.)

The localize utility, while in the public domain, is fully supported by its author (hussein AT pixware DOT com).

Install

Installing localize

Requirements

The localize utility has been tested with:

Install on Unix

Procedure:

  1. Unpack the localize distribution somewhere.
    $ cd 
    $ unzip localize-12.zip
    $ ls localize-12
    Localizer.java
    doc.html
    localize
    localize.bat
    localize.jar
  2. Copy the localize shell script and *.jar to a directory referenced in your path (example /usr/local/bin).
    $ su
    $ cp ~/localize-12/localize /usr/local/bin
    $ cp ~/localize-12/*.jar /usr/local/bin
    $ chmod a+rx /usr/local/bin/localize
    $ chmod a+r /usr/local/bin/*.jar

Install on Windows

Install on Windows is similar to the install on Unix but under Windows you'll have to copy localize.bat rather than the localize shell script.

Content of the distribution

localize, localize.bat
Scripts used to run this utility. (Use localize on any Unix system. Use localize.bat on Windows.)
localize.jar
contains the executable code of this utility.
Localizer.java
contains the source code of this utility.
doc.html
This user guide.

Command reference

localize ?options? jar_or_dir_name

Extract mode options are:

-x message_file
Extract messages to file message_file. Default: extract to console.
-l lang
Extract messages from '*_lang.properties'. Default: Extract from '[^_.]*.properties'.
-l2 lang2
If found, append corresponding message from '*_lang2.properties' after each message from '*_lang.properties'. Default: Append placeholder.

Patch mode options are:

-p message_file
Read messages from file message_file. Default: none (must be specified).
-l lang
Patch jar_or_dir_name with generated '*_lang.properties files'. Default: none (must be specified).

Other options are:

-v
Be verbose. Default: be quiet.

Case study: localizing XMLmind XML Editor

The reference language of XMLmind XML Editor (XXE) is English. This case study describes the localization of XXE in Spanish.

  1. Extract all the English messages from xxe_app.jar and put the extracted messages into file en_es.msg (the name of this file is not significant).
    $ localize -x en_es.msg xxe_app.jar

    The extracted message file is always encoded using the native encoding of the platform. Therefore, you can type accented characters as usual.

  2. Edit en_es.msg using a text editor and add a Spanish translation in each key= placeholder line.
                               . . . 
    styleSheetReloaded=Style sheet "{0}" reloaded.
    styleSheetReloaded=
    
    trimmingDocument=Stripping superfluous white space...
    trimmingDocument=
    
    undo=_Undo
    undo=
    
    untitled=Untitled
    untitled=
    
    userInput=User input
    userInput=
    
    viewClipboardContent=View Clipboard Content
    viewClipboardContent=
    
    window_menu=_Window
    window_menu=
    
    ----------com/xmlmind/xmleditapp/app/messages/Messages.properties
    ++++++++++com/xmlmind/xmleditapp/apt/messages/Messages.properties
    
    cancel=_Cancel
    cancel=
    
    defaultEncoding=_Default encoding:
    defaultEncoding=
                               . . . 

    Notes:

    Generating the same file for an already supported language may help you to better understand some of the messages.

    For example, if you understands French as well as English, this command will extract all English messages to file en_fr.msg, each English message being followed by the corresponding French message (if any):

    $ localize -x en_fr.msg -l2 fr xxe_app.jar
                               . . . 
    userInput=User input
    userInput=Action Utilisateur
    
    viewClipboardContent=View Clipboard Content
    viewClipboardContent=Afficher Contenu du Presse-Papier
    
    window_menu=_Window
    window_menu=Fenêtre
    
    ----------com/xmlmind/xmleditapp/app/messages/Messages.properties
    ++++++++++com/xmlmind/xmleditapp/apt/messages/Messages.properties
    
    cancel=_Cancel
    cancel=_Annuler
    
    defaultEncoding=_Default encoding:
    defaultEncoding=_Encodage par défaut:
                               . . . 

    This type of command must also be used if, for example, you have localized version 2.1 in spanish and want now to update your localization for version 2.2.

  3. Apply the edited en_es.msg to xxe_app.jar:
    $ localize -p en_es.msg -l es xxe_app.jar
    $ ls
                               . . .
    xxe_app.jar
    xxe_app.jar.BAK

    Note the mandatory -l argument used to specify which .properties file are to be generated.

  4. Run XXE to test your localization.

    Edit the shell script xxe on Unix (xxe.bat on Windows) and add -Duser.language=es in the java command line if the default locale of your desktop is not es.

  5. Repeat the first 4 steps with xxe.jar instead of xxe_app.jar.