Change language according to the locale
This Example shows you how to change language according to the locale. In the code given below we have changed language according to the locale.Methods used in this example are described below :
ResourceBundle.getBundle() : ResourceBundle class object holds locale-specific objects. When a program needs a locale-specific resource on that time program can load locale from the resource bundle that is suitable for the current user's locale. Method getBundle() returns a ResourceBundle class object using the specified name and locale.
MessageFormat.setLocale() : setLocale method use to set the locale in the MessageFormat class object.
ChangeLanguage.java
import java.text.*; |
ChoiceBundle.properties :
noFiles = are no files
|
ChoiceBundle_en_US.properties :
noFiles = are no files
|
ChoiceBundle_fr_FR.properties :
noFiles = n' y a pas des fichiers
|
output :
There are no files on desk.
|
Download code