Locale-Sensitive Data |
AroundTheWorld
When you first invokeAroundTheWorld
you 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,
AroundTheWorld
lets 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 runningAroundTheWorld
as 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.)
AroundTheWorld
is 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
CardLayout
object which helps you manage two or more components that share the same display space. In theAroundTheWorld
applet, theCardLayout
manages three LinguaPanels, one for each supported locale. EachLinguaPanel
contains the GUI elements for displaying the information for that locale. When the user chooses a new locale, theCardLayout
object shows the appropriateLinguaPanel
. Thus the bulk of the globalized code is in theLinguaPanel
class. (For complete information aboutCardLayout
and 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
ResourceBundle
s.
AroundTheWorld
defines four differentResourceBundle
ancestors:
LabelsBundle
--AListResourceBundle
that contains the text labels.NumbersBundle
--AListResourceBundle
that contains the numeric data.SoundBundle
--AnotherListResourceBundle
that contains the audio clips.ParagraphBundle
--APropertiesResourceBundle
that contains the paragraph description of the locale.When a
LinguaPanel
needs 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.
AroundTheWorld
uses 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 |