A Quick Example |
A properties files stores information about the characteristics of a program or environment. A properties file is in plain text format. You can create it with just about any text editor.In our example, the properties files store the translatable text of the messages we wish to display. Before our program was internationalized, the English version of this text was hardcoded in the
System.out.println
statements. Our default properties file, which is calledMessagesBundle.properties
, contains the following lines:Now that the messages are in a properties file, they can be translated into various languages. No changes to the source code are required. Our French translator has created a properties file calledgreetings = Hello farewell = Goodbye inquiry = How are you?MessagesBundle_fr_FR.properties
, which contains these lines:Notice that the values to the right side of the equal sign have been translated, but that the keys on the left side have not been changed. These keys must not change, because they will be referenced when your program fetches the translated text.greetings = Bonjour. farewell = Au revoir. inquiry = Comment allez-vous?The name of the properties file is important. The name of the
MessagesBundle_fr_FR.properties
file contains thefr
language code and theFR
country code. These codes are also used when creating aLocale
object.
A Quick Example |