Writing Global Programs |
Simply put, a global program is one that tailors its presentation of information to the user according to the user's preferred language and customs and therefore can be used comfortably by anyone, anywhere in the world.
Definition: A global program is a program that tailors the presentation of information to the user according to the user's preferred language and customs.
To better understand what a global program is, let's begin with a "myopic" program and watch its transformation into a global program. Along the way, this section will highlight the features of a global program.
What are the features of a myopic program? All of the language-dependent code and text are buried in the code alongside language-independent code and text. Text elements, such as labels for GUI elements and error messages, are written in "hacker-eze" (usually grammatically incorrect American English peppered with curses). The program is an amorphous blob of code and text with all sorts of language dependencies buried in the code:
At this point, some sales person in Europe says that the company could make millions if the program "spoke French and German". The programmers kick into high gear and create two new versions of the program: One that speaks French and the other that speaks German:
Modifying a program for use in a specific locale is called localization. Localization includes the obvious translation of GUI labels and error messages, but it also includes the customization of any feature for the target locale.
Definition: Localization is the process of adapting a program for use in a specific locale.
Often, when people think of localization, they think of creating a new version of a program on a per-country basis. However, country is not a good enough distinction. Consider Canada: English Canada and French Canada share many of the same laws, but a different language (and some very different language based laws). Thus, we use the term locale to mean some geographic or political region that shares the same language and customs.
Definition: A Locale is a geographic or political region that shares the same language and customs.
Localizing a myopic program in this manner has several problems:
- The programmer must create a new program for every new locale.
- Consequently, the programmer must maintain several copies of the same program thereby duplicating the entire program--even the language-independent parts.
- Each new locale requires a huge effort to locate and modify all of the language-dependent features of the program.
There must be a better way! Yes. There is.
Before localizing a program, the programmer should internationalize it. That is, the programmer should isolate the language-dependent parts of the program and separate them from the language-indepedent parts.
Definition: Internationalization is the process of isolating the language-dependent code in a computer program from the language-independent code.
Once internationalized, the program can be easily localized for each target locale. This is a truly global program:
Definition: A global program is one that has been internationalized and localized.
The Global Features of the JDK
When writing a program for the global market, programmers have many issues to consider: Character handling, bundling language-dependent resources, sorting (collation), text boundaries, and date and number formatting. Fortunately, the 1.1 release of the JDK contains many features that help programmers create global programs.
- As always, you write Java programs in Unicode--a 16-bit international character encoding standard. Unicode has the capacity to represent over 65,000 characters--ample enough to include characters for most of the languages common today.
The JDK 1.1 added font support for Unicode characters. See [PENDING] for information.
[PENDING: add note about character set conversion]
- In Java, locales are not a global attribute of the whole program. Rather, each locale-sensitive object maintains its own locale-specific information. Locale-sensitive operations require a Locale object as an argument. This design is quite flexible and, in addition to other nifty things, allows a program to use and display multiple Locales at the same time. What Are Locales and How Do I Use Them? later in this lesson covers the Locale class and its use.
In addition, the JDK itself provides support for many of the more common locales, such as France, Germany, the various regions of Canada and so on.
- Java provides several classes that help you bundle resources, such as strings and other language-dependent objects, within your global programs. Managing Locale-Sensitive Data covers managing strings and other objects in a language-independent manner.
- Formatting of numbers and dates is another locale-sensitive feature of many programs. For example, what date does the following represent: 12/1/97? Your answer depends on where you live. In some locales, the date is December 1, 1997, in others, January 12, 1997. A significant difference if you're talking about deadlines or a child's birthday.
The JDK 1.1 provides several classes that allow a program to display dates, numbers and currency in a locale-sensitive way. These features of the JDK are covered thorougly in Formatting and Parsing.
- [PENDING: Put an introduction to collation here.]
- The remaining features of the JDK that provide you with the tools you need to write a global program fall into the category of advanced features. Many programmers may never need these features. But programmers writing programs that perform any sort of complicated text manipulation (such as a word processor) may. These features include: [PENDING]
Writing Global Programs |