Chapter 5 Supporting Local Conventions

As we saw in Chapter 3, character encoding is the most basic foundation for any form of text processing; if it's handled poorly, the software will be next to impossible to localize, let alone to internationalize. But good character encoding is only half the battle—a program also requires functionality that observes language rules and cultural conventions. Microsoft Windows provides generic support for linguistic and cultural conventions through the Microsoft Win32 NLSAPI, which carries information on date, time, calendar, number, and currency formats. The API also provides sorting and character-type information for all the locales supported by the operating system.

Windows 3.x provided 22 pieces of locale-related information in the [intl] section of WIN.INI. The system registries of Microsoft Windows NT and Microsoft Windows 95, which contain more than 90 locale-related strings, are far more comprehensive. The Win32 NLSAPI allows an individual application to request information for any locale, whereas Windows 3.x limited all applications running on the system to the settings of the current default locale.

A great deal of linguistic research went into creating the collection of locale information in the registry and into the algorithms and tables used by the NLSAPI. You'll save yourself a lot of trips to the library, as well as the drudgery of maintaining locale information and code, by taking advantage of what the system offers. Generic code based on the NLSAPI will work for any locale the system supports. If support for additional locales is added to Windows, an existing application that calls the NLSAPI will automatically support cultural conventions for those locales. In such a case, users can perform basic tasks with the existing application while they wait for something more fully localized, as long as the version of Windows they are using supports the desired locale.

Like the rest of the Win32 API, the NLSAPI exists in two forms: one form takes parameters and returns results in Unicode, and the other works with local character sets. The results of the API calls are identical, except that the -A APIs return data for the local code page only. Localized month names, for example, are intelligible only if they can be expressed in the local character set. On Windows NT, you can use either the -W or the -A API call. On Windows 95, only the -A functions are available. (Their wide-character counterparts are stubbed.)

If you are interested in cross-platform functionality, Microsoft Visual C++ 2's run-time libraries offer a number of locale-sensitive functions, many of which correspond to NLSAPI calls. Some of the wide-character functions, which work on all versions of Win32, are listed in Chapter 3. For more information on how to use the C run-time functions, consult your current Visual C++ documentation.