A Quick Example |
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 theResourceBundle
with thegetString
method. For example, to retrieve the message identified by the greetings key, we would invokegetString
as follows:In our example, we've used the key greetings because it reflects the content of the message, but we could have used some otherString msg1 = messages.getString("greetings");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.
A Quick Example |