how to add multi language support in java application

by rajesh 2009-12-30 17:04:20

To give multi language support in Graphical User Interface (GUI) of any java application.
We have to use java.util.ResourceBundle to do this.

We have to make different property files for the different languages.
Name of all property files should be same with additional language suffix.
For exp. fr for French, de for German etc.

Label.properties file for the English
Label_fr.properties file for the French

In both the files we will have the strings and their translated strings
Now we can read from the the property files using ResourceBundle as

Example:


package test;

import java.util.Locale;
import java.util.ResourceBundle;

public class MultiLanguage {

  public static void main(String[] args) {

    ResourceBundle resourceBundle = ResourceBundle.getBundle("test.label", Locale.FRENCH);

    String name = resourceBundle.getString("NAME");

    System.out.println(name);
    
  }

}


The above example will read from Label_fr.properties and print the french value of NAME

Tagged in:

2728
like
0
dislike
0
mail
flag

You must LOGIN to add comments