1. Technology

Internationalization

By

Definition:

It's not always obvious to a developer that the user using their application does not speak the same language as them. Who knows if the user is only knows French, Spanish or German? Internationalization is the term given to making an application adaptable to different languages without the need to change any code.

The main goals behind an internationalized program is provide a compiled executable which can leverage of localized data to transform it's GUI interface from one language to another. This means the localized data needs to be stored outside of the compiled code and dynamically added to the interface at run time. Any documentation or help files also need to be available in the other language(s). Lastly it's also possible that sounds or images might not be usable in some countries due to cultural differences. As always the more you know about your intended user the more useful an application is going to be.

These kinds of changes inevitably lead to a change in programming style for the developer. For example, hard coded Strings are no use at all:

public class ConstMessages{
    public static final String A_MESSAGE = "I'm always going to be in English.";
    public static final String B_MESSAGE = "You might not understand this.";
}
    

If those constants are used inside the compiled application any future internationalization will involve the application code to be changed and recompiled. 

Instead property files can be used in Java applications to handle international text. A property file is simply a text file with key value pairs for each bit of text. For example,

Save=Retten
Open=Offen
Print=Drucken
    

could be saved in a property file called ApplicationText_de.properties.

Then the appropriate text can be loaded in to the application at run time using the ResourceBundle class:

ResourceBundle textMessages = ResourceBundle.getBundle("ApplicationText", locale_de);
String openTxt = textMessages.getString("Open");
    
The key to getting the right language text is the locale object. There may be many ApplicationText_<countrycode>.properties files so setting the locale of the user is essential.
Locale locale_de = new Locale("de");

All that needs to happen is for the user to pick the locale either when installing the application or as part of a change language function of the user interface. Or you can choose to use the default locals as stored by the operating system of the user.

Every language has a lowercase two character code as defined by an ISO standard. Likewise every country has an uppercase two character code. For example, German de, Dutch nl, French fr; Germany DE, The Netherlands NL, France FR.

Once you have a locale object created it can be used to set the number formats for that location to. After all it's not just text that will need to change the way it is displayed.

Glossary:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  1. About.com
  2. Technology
  3. Java
  4. Java Glossary
  5. I
  6. Java Term: Internationalization

©2014 About.com. All rights reserved.