How to perform Multilanguage Support in Java Programing Language
We can Do multilanguage support using Java.util package's ResourceBundle Class.
Steps to give multilanuage support in Java
1. Create Property file with name MessagesBundle.properties
2. Create Property file in each language with language code extension
ex:
MessagesBundle_en_US.properties //For english US Local
MessagesBundle_fr_FR.properties //fr- french FR- For France
MessagesBundle_cn_CN.properties
3. Add the language datas in property file as below
i) Open MessageBundle.properties
ii) Add the Words to be translated in Key value format like below
# In MessagesBundle_en_US.properties and MessagesBundle.properties file
name=Name
hello=Hello
4. Similarly Add for other Languages
#MessagesBundle_fr_FR.properties file
name=Nom
hello=Bonjour
4. Create java program to use the property file
import java.util.Local;
import java,util.ResourceBundle;
public multiLanguage{
public static void main(String arg[]){
Locale currentLocale= new Locale("fr", "FR");
ResourceBundle rb = ResourceBundle.getBundle("MessagesBundle", currentLocale);
System.out.println(rb.getString("hello"));
}
}
Note:
1. Keys in Progperty file Should not have any spaces and special characters
2. Place the java classes and property file should be in same directory
How to Add Multilanguage support in JSP
It is similar to Giving multilanguage support in Java the only difference is here we have to place the property file in "WEB-INF/classes" folder
