|
|
Locale-Sensitive Data |
AroundTheWorld
When you first invokeAroundTheWorldyou see a window that looks like this:
![]()
You use the flag symbols at the top of the window to choose a new locale. The currently selected locale is indicated by a thick border around the flag. When you select a new locale, the window changes to display useful tidbits of information about that locale: the name of the locale, today's date, the current time in a city representative of the locale, the per capita GDP, the population, the literacy rate, and a brief paragraph describing the region. (These tidbits were retrieved from the CIA's 1994 World Fact book on the Internet).
In addition to the facts displayed about each locale,
AroundTheWorldlets you to play the words book, car, dog, and apple in the language that is dominant in the selected locale. Note: this works only if you are runningAroundTheWorldas an applet. Sounds aren't available to stand-alone programs. (Our thanks to Patrick Chan for writing the WordMatch applet from which we swiped these images and sounds.)
AroundTheWorldis a global program--it's completely internationalized and it's been localized for three locales: the United States, France, and the United Kingdom.The Classes
The IntlWindow class implements the main window of the program. This window is divided into two functional areas. The first area, shown below, is the control area. The objects in the control area (panels, canvases, and images) are shared by all locales.
![]()
The rest of the window is the display area.
![]()
The display area is laid out by a
CardLayoutobject which helps you manage two or more components that share the same display space. In theAroundTheWorldapplet, theCardLayoutmanages three LinguaPanels, one for each supported locale. EachLinguaPanelcontains the GUI elements for displaying the information for that locale. When the user chooses a new locale, theCardLayoutobject shows the appropriateLinguaPanel. Thus the bulk of the globalized code is in theLinguaPanelclass. (For complete information aboutCardLayoutand for another example that uses one, see How to Use CardLayout.)The data that you see and hear in the display area is locale-sensitive and is contained in
ResourceBundles.
AroundTheWorlddefines four differentResourceBundleancestors:
LabelsBundle--AListResourceBundlethat contains the text labels.NumbersBundle--AListResourceBundlethat contains the numeric data.SoundBundle--AnotherListResourceBundlethat contains the audio clips.ParagraphBundle--APropertiesResourceBundlethat contains the paragraph description of the locale.When a
LinguaPanelneeds to display information, it retrieves the information from the resource bundle that contains the appropriate data. Thus, all the locale-specific data for the program is isolated in resource bundles and is not intermingled with other, locale-independent code.
AroundTheWorlduses several of the internationalization features of the JDK 1.1, including locales, resource bundles, calendar (and time zone) support, and formatting of date, currency, percent, and number data.Future Improvements to
AroundTheWorld
- the Per Capita GDP numbers for France and Great Britain are actually United States dollars data formatted as the currency for the current locale. The numbers are way off.
- get "real" translations and data for the non-US locales
- have a list to sort (collation)
- support a non-western language such as Japanese
- do text and word boundaries in the text area
- character set conversion
- I/O
- name attribute, locale attribute (actually we already do locale attribute by getting the locale from the window)
|
|
Locale-Sensitive Data |