This tip will show how to add multi-lingual feature in Graphical User Interface (GUI) of any java application. To run any GUI of java application in multiple language java.util.ResourceBundle is used.
First make different property files for the different language. Name of all property files should be same with additional language suffix. For exp. fr for French, de for German etc.
For example-
· Label.properties file for the English
· Label_fr.properties file for the French
Now use the following code to read the property file according to the Locale.
package myProject;
import java.util.Locale; import java.util.ResourceBundle; public class TextReader { public static void main(String[] args) { ResourceBundle resourceBundle = ResourceBundle.getBundle( "myProject.label", Locale.FRENCH); String name = resourceBundle.getString("NAME"); String password=resourceBundle.getString("PASSWORD"); System.out.println(name); System.out.println(password); } } |
Comments
Post a Comment