Java Localization

Localtransformer supports localizing of Java applications . In order to do that Java properties files are being used. Java properties files i.e. Resource bundles consist of key/value pairs. Locale specific resource bundles have a filename that consists of the name of the resource bundle followed by the "_" character and the locale code. For example, if the filename of the resource bundle is LocaltransformerStrings.properties then the localized German version (locale "de") of the resource bundle will have a filename LocaltransformerStrings_de.properties.
In order to localize Java applications the following steps have to be made

Step 1 - Internationalize Application

At first the application should be internationalized. This means that it should be made ready for localization. All strings and messages that are to be localized should be put in separate Java properties files. Therefore, it is necessary to add a Java properties file to your Java project and add a name and value pair for each string or message that is to be localized.
An example of the contents of a Java properties file is the following:

# Localtransformer Demo properties file
title=Products Purchase
label2=Write the Locale in the Textbox
label3=Then press the Change Language Button
buttonChange=Change Language
label5=Product : Mobile Phone KTS 1000
buttonBuy=Buy

Step 2 - User Interface Language Switching Code

After making localization ready the application , it is necessary to add code in the application that enables to switch the language of the user interface. This can be done with a few lines of code.
Add a class member for the Resource Bundle for example:

private ResourceBundle resStrings;

And also include java.util in the class. Then in order to switch language add the following lines of code

try {
resStrings = ResourceBundle.getBundle("LocalTransformerStrings", new Locale("de"));
UpdateDisplayWithLocalStrings();
}
catch (Exception e)
{
...
}


In order to update the display we execute the UpdateDisplayWithLocalStrings function which is defined as:

private void UpdateDisplayWithLocalStrings()
{
this.setTitle(resStrings.getString("title"));
label2.setText(resStrings.getString("label2"));
label3.setText(resStrings.getString("label3"));
label5.setText(resStrings.getString("label5"));
buttonChange.setText(resStrings.getString("buttonChange"));
buttonBuy.setText(resStrings.getString("buttonBuy"));
}


As you can see in order to get the localized strings we execute the resStrings.getString function with the message key as a parameter.
For more information have a look at the Java demo application in your Localtransformer directory.

Step 3 - Run Localtransformer and scan the Java properties file

After doing all this we have to run Localtransformer and create a new project where we will add the Java properties file of the application. Localtransformer will scan the application and extract all data to be localized.

Step 4 - Export or Send Project to Translator

The next step is to export the data to be localized (for example as a csv text file) or send the project to the translator

Step 5 - The translator translates the data to be localized

Then , the translator can edit the export file (for example it is possible to edit the exported csv text file in Microsoft Excel) or open the Localtransformer project and translate it within Localtransformer.

Step 6 - The translator sends the translated export file or project back

After having translated the data to be localized the translator should send it back.

Step 7 - Import the localized files from the translator

Then, it is necessary to import the localized file that the translator sent.

Step 8 - Build the localized Java properties file with Localtransformer

In the end , build the localized Java properties file with the use of Localtransformer.