java tutorial - ResourceBundle class in Java - java programming - learn java - java basics - java for beginners
- The ResourceBundle class is utilized to internationalize the messages. At the end of the day, we can state that it gives a system to globalize the messages.
- The hardcoded message isn't viewed as great as far as programming, since it contrasts starting with one nation then onto the next.
- So we utilize the ResourceBundle class to globalize the back rubs.
- The ResourceBundle class stacks these informations from the properties record that contains the messages.
- Expectedly, the name of the properties document ought to be filename_languagecode_country code for instance MyMessage_en_US.properties.
Methods of ResourceBundle class
- There are many methods used ResourceBundle class.
- public static ResourceBundle getBundle(String basename) returns the instance of the ResourceBundle class for the default locale.
- public static ResourceBundle getBundle(String basename, Locale locale) returns the instance of the ResourceBundle class for the specified locale.
- public String getString(String key) returns the value for the corresponding key from this resource bundle.
- Below example creating three files:
- MessageBundle_en_US.properties file contains the localize message for US country.
- MessageBundle_in_ID.properties file contains the localize message for Indonaisa country.
- InternationalizationDemo.java file that loads these properties file in a bundle and prints the messages.