Remember the pages for setting user preferences from Chapter 9? One of the pages allows the user to select her preferred language; let’s add what’s needed for actually using the selected language. Figure 11-1 shows one of the preferences pages when Swedish is selected as the preferred language.
Java was designed with internationalization in mind and includes a
number of classes to make the process as painless as possible. In
i18n terminology, a locale represents a specific
geographical region. In Java, a locale is represented by an instance
java.util.Locale class. Java includes other
classes for formatting dates and numbers according to the rules
defined for a locale, and classes to help you include localized
strings and other objects in an application.
You create a
a constructor that takes a country code and language code as
java.util.Locale usLocale = new Locale("en", "US");
Locale for U.S. English is created. George Bernard Shaw (a famous Irish playwright) once observed, “England and America are two countries divided by a common language,” so it’s no surprise that both a language code and a country code are needed to describe some locales completely. The language code, a lowercase two-letter combination, is defined by the ISO 639 standard ...