Internationalization

The ANSI standard supports the development of C programs that are adaptable to language and country-specific customs, such as the formatting of currency strings. The ANSI library also provides two functions, the type lconv, and macros for dealing with locales. These are declared in the header file locale.h .

All programs start with the default locale “C”, which contains no country or language-specific information. During execution, the program can change to another locale and retrieve locale-specific information. Since most applications do not require the full range of locale-specific information, this information is classified into categories, as shown in Table 1-42.

Table 1-42. Locale categories

Category

Portions of the locale affected

LC_ALL

The entire locale, including all of the categories below

LC_COLLATE

Only the functions strcoll() and strxfrm()

LC_CTYPE

Functions for character processing, such as isalpha() and the multibyte functions

LC_MONETARY

The currency formatting information returned by localeconv()

LC_NUMERIC

The decimal point character used by input/output and string conversion functions, and the formatting of non-currency numeric information, as returned by localeconv()

LC_TIME

Formatting of date and time information by strftime()

The following function is used to adapt a program to a specific locale:

char *setlocale( int category, const char *name );

The argument category is one of the symbolic constants described ...

Get C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.