setlocale(3int)
NAME
setlocale − set localization for internationalized program
SYNTAX
#include <locale.h>
char *setlocale (category, locale)
int category;
char *locale;
DESCRIPTION
The setlocale function selects the particular area as the program’s environment for localization. The localization area is specified by the category argument and can be used to change or query the internationalization environment that the program is running under. The values for category are shown in the following table:
| Value | Resulting Changes | Environment |
| LC_ALL | Sets or queries entire environment | LANG |
| LC_COLLATE | Change or query collation sequences | LC_COLLATE |
| LC_CTYPE | Change or query character classification | LC_TYPE |
| LC_NUMERIC | Change or query radix character | LC_NUMERIC |
| LC_TIME | Change or query time conversion parameters | LC_TIME |
| LC_MONETARY | Change or query monetary information | LC_MONETARY |
The locale argument is a pointer to a character string containing the required setting of category. The contents of this string are defined in lang. There are a number of preset values of locale defined for all the settings of category:
"C" Specifies the minimal environment for C language translations. If setlocale is not invoked, the C locale is the default.
"" Specifies the use of the environment variable corresponding to category. If the appropriate environment variable is not set, the LANG environment variable is used. If this is not set, an error is returned (see environ).
NULL
This is used to query the current international environment and return the name of the current locale. This string may only be used as input to a subsequent setlocale call; in particular it is not printable for category LC_ALL. The returned string points to a static data area which may be overwritten.
The setlocale function can be used to bind the specific language requirements of a user to the program as follows:
setlocale (LC_ALL, "");
NOTE
When a C program is compiled the −li option must be used to include the internationalization library, for example: cc −o prog prog.c −li
RETURN VALUES
If the selection for the setlocale function is valid, the locale is changed and the string associated with the category of the new locale is returned. In this case, selection means the combination of locale and category. If any selection is invalid, the program’s locale remains unchanged.
It is not possible to change more than one part of the program’s locale in a single call to setlocale, unless the category used is LC_ALL.
If locale is a null pointer, setlocale returns the string associated with category for the current locale. The current locale is unchanged. Note that this string may not be in a printable form.
If the string returned by setlocale is used in a subsequent call with its associated category, it restores that part of the program’s locale.
The string returned by setlocale should not be modified by the user and may be overwritten by subsequent calls to setlocale.
EXAMPLES
The following examples show an environment that is set to use the French language, and then has the collating sequence modified.
setlocale (LC_ALL, "FRE_FR.MCS");
setlocale (LC_COLLATE, "GER_DE.MCS");
SEE ALSO
extract(1int), gencat(1int), ic(1int), strextract(1int), strmerge(1int), trans(1int), atol(3), conv(3), ctype(3), ecvt(3), catgetmsg(3int), catgets(3int), catopen(3int), nl_langinfo(3int), nl_printf(3int), nl_scanf(3int), strcoll(3int), strftime(3int), strxfrm(3int), printf(3s), scanf(3s), environ(5int), lang(5int), nl_types(5int), patterns(5int)
Subroutines