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.
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.
February 26, 2012
can run the program
this Exception is thrown when i run the program :
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name ChoiceBundle, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
November 17, 2013
You need to add the location of the Java bundle file:
ResourceBundle bundle = ResourceBundle.getBundle("languagetest.ChoiceBundle", currentLocale);