[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

National Language Support Guide and Reference

Setting the Locale

Every internationalized program must set the current locale using the setlocale subroutine. This subroutine allows a process to change or query the current locale by accessing locale databases.

When a process is started, its current locale is set to the C or POSIX locale. A program that depends on locale data not defined in the C or POSIX locale must invoke the setlocale subroutine in the following manner before using any of the locale-specific information:

setlocale(LC_ALL, "");

Accessing Locale Information

The following subroutines provide access to information defined in the current locale as determined by the most recent call to the setlocale subroutine:

localeconv
Provides access to locale information defined in the LC_MONETARY and LC_NUMERIC categories of the current locale. The localeconv subroutine retrieves information about these categories, places the information in a structure of type lconv as defined in the locale.h file, and returns a pointer to this structure.
nl_langinfo
Returns a pointer to a null-terminated string containing information defined in the LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME categories of the current locale.
rpmatch
Tests for positive and negative responses, which are specified in the LC_MESSAGES category of the current locale. Responses can be regular expressions, as well as simple strings. The rpmatch subroutine is not an industry-standard subroutine, portable applications should not assume that this subroutine is available.

The localeconv and nl_langinfo subroutines do not provide access to all LC_* categories.

The current locale setting for a category can be obtained by: setlocale(Category, (char*)0). The return value is a string specifying the current locale for Category. The following example determines the current locale setting for the LC_CTYPE category:

char *ctype_locale; ctype_locale = setlocale(LC_CTYPE, (char*)0);

Examples

Time Formatting Subroutines

Programs that need to format time into wide character code strings can use the wcsftime subroutine. Programs that need to convert multibyte strings into an internal time format can use the strptime subroutine.

In addition to the strftime subroutine defined in the C programming language standard, X/Open Portability Guide Issue 4 defines the following time formatting subroutines:

wcsftime
Formats time into wide character code strings
strptime
Converts a multibyte string into an internal time format

Examples

Monetary Formatting Subroutines

Programs that need to specify or access monetary quantities can call the strfmon subroutine.

Although the C programming language standard in conjunction with POSIX provides a means of specifying and accessing monetary information, these standards do not define a subroutine that formats monetary quantities. The XPG4 strfmon subroutine provides the facilities to format monetary quantities. No defined subroutine converts a formatted monetary string into a numeric quantity suitable for arithmetic. Applications that need to do arithmetic on monetary quantities may do so after processing the locale-dependent monetary string into a number. The culture-specific monetary formatting information is specified by the LC_MONETARY category. An application can obtain information pertaining to the monetary format and the currency symbol by calling the localeconv subroutine.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]