locale (7) - Linux Manuals
locale: description of multilanguage support
NAME
locale - description of multilanguage support
SYNOPSIS
#include <locale.h>
DESCRIPTION
A locale is a set of language and cultural rules. These cover aspects such as language for messages, different character sets, lexicographic conventions, and so on. A program needs to be able to determine its locale and act accordingly to be portable to different cultures.The header <locale.h> declares data types, functions and macros which are useful in this task.
The functions it declares are setlocale(3) to set the current locale, and localeconv(3) to get information about number formatting.
There are different categories for locale information a program might need; they are declared as macros. Using them as the first argument to the setlocale(3) function, it is possible to set one of these to the desired locale:
- LC_ADDRESS (GNU extension, since glibc 2.2)
- Change settings that describe the formats (e.g., postal addresses) used to describe locations and geography-related items. Applications that need this information can use nl_langinfo(3) to retrieve nonstandard elements, such as _NL_ADDRESS_COUNTRY_NAME (country name, in the language of the locale) and _NL_ADDRESS_LANG_NAME (language name, in the language of the locale), which return strings such as "Deutschland" and "Deutsch" (for German-language locales). (Other element names are listed in <langinfo.h>.)
- LC_COLLATE
- This category governs the collation rules used for sorting and regular expressions, including character equivalence classes and multicharacter collating elements. This locale category changes the behavior of the functions strcoll(3) and strxfrm(3), which are used to compare strings in the local alphabet. For example, the German sharp s is sorted as "ss".
- LC_CTYPE
- This category determines the interpretation of byte sequences as characters (e.g., single versus multibyte characters), character classifications (e.g., alphabetic or digit), and the behavior of character classes. On glibc systems, this category also determines the character transliteration rules for iconv(1) and iconv(3). It changes the behavior of the character handling and classification functions, such as isupper(3) and toupper(3), and the multibyte character functions such as mblen(3) or wctomb(3).
- LC_IDENTIFICATION (GNU extension, since glibc 2.2)
- Change settings that relate to the metadata for the locale. Applications that need this information can use nl_langinfo(3) to retrieve nonstandard elements, such as _NL_IDENTIFICATION_TITLE (title of this locale document) and _NL_IDENTIFICATION_TERRITORY (geographical territory to which this locale document applies), which might return strings such as "English locale for the USA" and "USA". (Other element names are listed in <langinfo.h>.)
- LC_MONETARY
- This category determines the formatting used for monetary-related numeric values. This changes the information returned by localeconv(3), which describes the way numbers are usually printed, with details such as decimal point versus decimal comma. This information is internally used by the function strfmon(3).
- LC_MESSAGES
- This category affects the language in which messages are displayed and what an affirmative or negative answer looks like. The GNU C library contains the gettext(3), ngettext(3), and rpmatch(3) functions to ease the use of this information. The GNU gettext family of functions also obey the environment variable LANGUAGE (containing a colon-separated list of locales) if the category is set to a valid locale other than "C". This category also affects the behavior of catopen(3).
- LC_MEASUREMENT (GNU extension, since glibc 2.2)
- Change the settings relating to the measurement system in the locale (i.e., metric versus US customary units). Applications can use nl_langinfo(3) to retrieve the nonstandard _NL_MEASUREMENT_MEASUREMENT element, which returns a pointer to a character that has the value 1 (metric) or 2 (US customary units).
- LC_NAME (GNU extension, since glibc 2.2)
- Change settings that describe the formats used to address persons. Applications that need this information can use nl_langinfo(3) to retrieve nonstandard elements, such as _NL_NAME_NAME_MR (general salutation for men) and _NL_NAME_NAME_MS (general salutation for women) elements, which return strings such as "Herr" and "Frau" (for German-language locales). (Other element names are listed in <langinfo.h>.)
- LC_NUMERIC
- This category determines the formatting rules used for nonmonetary numeric values---for example, the thousands separator and the radix character (a period in most English-speaking countries, but a comma in many other regions). It affects functions such as printf(3), scanf(3), and strtod(3). This information can also be read with the localeconv(3) function.
- LC_PAPER (GNU extension, since glibc 2.2)
- Change the settings relating to the dimensions of the standard paper size (e.g., US letter versus A4). Applications that need the dimensions can obtain them by using nl_langinfo(3) to retrieve the nonstandard _NL_PAPER_WIDTH and _NL_PAPER_HEIGHT elements, which return int values specifying the dimensions in millimeters.
- LC_TELEPHONE (GNU extension, since glibc 2.2)
- Change settings that describe the formats to be used with telephone services. Applications that need this information can use nl_langinfo(3) to retrieve nonstandard elements, such as _NL_TELEPHONE_INT_PREFIX (international prefix used to call numbers in this locale), which returns a string such as "49" (for Germany). (Other element names are listed in <langinfo.h>.)
- LC_TIME
- This category governs the formatting used for date and time values. For example, most of Europe uses a 24-hour clock versus the 12-hour clock used in the United States. The setting of this category affects the behavior of functions such as strftime(3) and strptime(3).
- LC_ALL
- All of the above.
If the second argument to setlocale(3) is an empty string, "", for the default locale, it is determined using the following steps:
- 1.
- If there is a non-null environment variable LC_ALL, the value of LC_ALL is used.
- 2.
- If an environment variable with the same name as one of the categories above exists and is non-null, its value is used for that category.
- 3.
- If there is a non-null environment variable LANG, the value of LANG is used.
Values about local numeric formatting is made available in a struct lconv returned by the localeconv(3) function, which has the following declaration:
struct lconv {