Localization API

Starting with Wrapper version 3.5.0, the code base has been internationalized and is able to run localized. The internationalizations and localization method of the Wrapper may also be used to localize your Java Applications with relatively little coding effort.

The basic steps for implementing a Wrapper based localization are:

You can localize your application to any language your distribution supports and with any OS. Japanese, Spanish, German, French, Russian, Chinese, Korean, Italian, Portuguese, Dutch, Danish, Hungarian, Hindi, Greek, Arabic, Romanian, Ukrainian, Turkish, Malay. (If you are missing a language you wish, please feel free to contact us, and we will add the language in the next release.)

1. Add WrapperResources instance

To utilize the localization methods of the Wrapper, you need to add a WrapperResources instance. The most recommended way is to place a static variable holding the WrapperResources instance in a unique class of your project and create a static "getter" method. This way the classes of your project can access the WrapperResource and localize messages. In the getter method you can create the WrapperResource class by calling WrapperManager.loadWrapperResources(java.lang.String, java.lang.String).

static WrapperResource instance & getter method
private static WrapperResources m_res;

public static WrapperResources getRes()
{
    if ( m_res == null )
    {
            // Synchronize and then recheck to avoid this method always synchronizing.
            synchronized( Unique.class )
            {
                if ( m_res == null )
                {
                    m_res = WrapperManager.loadWrapperResources( "myapp",
                        WrapperSystemPropertyUtil.getStringProperty( "wrapper.lang.folder", "../lang" ) );
                }
            }
    }
    return m_res;
}

The first parameter of WrapperManager.loadWrapperResources() is the domain, i.e. the name upon the Wrapper will try to load the resource file. For instance, if the above getter the Wrapper will try to load the myapp_XX.mo (XX is the language abbreviation) from the location specified in the wrapper.lang.folder property. If this property isn't set, it will try to load from "../lang".

2. Flag the messages for localization

Flagging all the messages you want to localize is most likely the most time consuming part in setting up the localization. You need to go through your project and wrap your messages with the getString() method.

plain getString example
System.out.println( Unique.getRes().getString( "A test message." ) );

If you need to put variables into your output, please use the getString(java.lang.String, java.lang.Object[]) method. All variables are put into the Object array. For convenience the WrapperResources provides also some wrapper-methods for up to 5 Objects.

getString example with 2 variables
int number = 2;
String msg = "test";
System.out.println( Unique.getRes().getString( "A {0} message with {1} variables.", msg, number ) );

The first parameter of the getString() method can also define various formats. For more information on this, please have a look at the "java.text.MessageFormat documentation".

NOTE

Please note that Java versions below 1.6 can't cast primitive types (int, boolean, float, etc.) to Objects. In this case, please consider using the corresponding Wrapper class (java.lang.Integer, java.lang.Boolean, java.lang.Float, etc.)

3. Create and prepare mo files

The layout of the localization process of the Wrapper is similar to GNU gettext. Therefore the easiest way is to create the message resource template with xgettext.

Use xgettext to create message resource template:
xgettext -d myapp -o ./lang/myapp.pot [project source files]

This will create a pot file. Please note that for Java files, xgettext looks for the keyword "getString("..")". If you want to add another keyword please add them with the parameter "-k [keyword]". The resource files for any language is based on this template. To create a resource file for a certain language run:

Use xgettext to create message resource:
msginit --locale=ja --input=./lang/myapp.pot --output=./lang/myapp_ja.po

This will resolve in an editable po file. You or your translator can start translating this po file. She/he can either use a plain text editor or an editor (e.g. "poedit", or "Gtranslator", etc.) for po files.

After the translation has been finished, please compile the po file (using a po editor or msgfmt), which will resolve in the binary mo file. If not already done, place the mo file to the other mo files of the Wrapper. Your application has been localized!

The localization setup for Your application has been finished! For information on how to run your application, please have a look at the wrapper.lang properties.