A Quick Example |
ResourceBundle
objects contain locale-specific objects. You useResourceBundle
objects to isolate locale-sensitive data, such as translatable text. In our sample program, theResourceBundle
is backed by the properties files which contain the message text we want to display.Our
ResourceBundle
is created as follows:The arguments passed to themessage = ResourceBundle.getBundle("MessagesBundle",currentLocale)getBundle
method identify which properties file we want to access. The first argument,MessagesBundle
, refers to this family of properties files:TheMessagesBundle_en_US.properties MessagesBundle_fr_FR.properties MessagesBundle_de_DE.propertiesLocale
, which is the second argument ofgetBundle
, specifies which of theMessagesBundle
files is chosen. When theLocale
was created, the language code and country code were passed to its constructor. Note that the language and country codes followMessagesBundle
in the names of the property files.Now, all we have to do is get the translated messages from the
ResourceBundle
.
A Quick Example |