An application sets up its international environment at run-time by calling the setlocale function. The international environment is set up in one of two ways:
The syntax for the setlocale function is:
char *setlocale(int category, const char *locale)
Where:
If you want users to specify the locale interactively, your application could prompt the user for a locale name, and then pass the name as an argument to the setlocale function. A locale name has the following format:
language_country.codeset[@modifier]
For example, setlocale(LC_COLLATE,
"en_US.ISO8859-1")
selects the locale en_US.ISO8859-1
for the LC_COLLATE category.
This causes the function to use logical names to determine the locale for the category specified. See Specifying the Locale Using Logical Names for details.
If an application does not call the setlocale function, the default locale is the C locale. This allows such applications to call those functions that use information in the current locale.
Specifying the Locale Using Logical Names
If the setlocale function is called with "" as the locale argument, the function checks for a number of logical names to determine the locale name for the category specified.
There are a number of logical names that users can set up to define their international environment:
For example, the LC_NUMERIC logical name defines the locale associated with the LC_NUMERIC category within the user's environment.
The LANG logical name defines the user's language.
In addition to the logical names defined by a user, there are a number of system-wide logical names, set up during system startup, that define the default international environment for all users on a system:
Where category is the name of a category. This specifies the system default for that category.
The setlocale function checks for user-defined logical names first, and if these are not defined, it checks the system logical names.