Previous | Next | Trail Map | Internationalization | A Quick Example

Fetching the Text from the ResourceBundle

The properties files contain key/value pairs. The values consist of the translated text that our program will display. We'll specify the keys when we fetch the translated messages from the ResourceBundle with the getString method. For example, to retrieve the message identified by the greetings key, we would invoke getString as follows:
String msg1 = messages.getString("greetings");
In our example, we've used the key greetings because it reflects the content of the message, but we could have used some other String, such as s1 or msg1. Just remember that the key is hardcoded in your program, and it must be present in the properties files. If your translators accidentally modify the keys in the properties files, getString won't be able to find the messages.

That's it. As you can see, internationalizing a program isn't too difficult. It requires some planning, and a little extra coding, but the benefits are enormous. The example we've covered in this section was intentionally simple, because we wanted to provide you with an overview of the internationalization process. The Java APIs offer much more capabilities in internationalization than described in this section. We'll discuss these topics in greater detail in the sections that follow.


Previous | Next | Trail Map | Internationalization | A Quick Example