Time 201
Locale information is maintained in a directory hierarchy under /usr/share/
locale (or /usr/lib/locale in some distributions). Each subdirectory under this direc-
tory contains information about a particular locale. These directories are named
using the following convention:
language[_territory[.codeset]][@modifier]
The language is a two-letter ISO language code, and the territory is a two-letter ISO
country code. The codeset designates a character-encoding set. The modifier pro-
vides a means of distinguishing multiple locale directories whose language, terri-
tory, and codeset are the same. An example of a complete locale directory name is
de_DE.utf-8@euro, as the locale for: German language, Germany, UTF-8 character
encoding, employing the euro as the monetary unit.
As indicated by the brackets shown in the directory naming format, various
parts of the name of a locale directory can be omitted. Often the name consists of
just a language and a territory. Thus, the directory en_US is the locale directory for
the (English-speaking) United States, and fr_CH is the locale directory for the
French-speaking region of Switzerland.
The CH stands for Confoederatio Helvetica, the Latin (and thus locally language-
neutral) name for Switzerland. With four official national languages, Switzer-
land is an example of a locale analog of a country with multiple timezones.
When we specify a locale to be used within a program, we are, in effect, specifying
the name of one of the subdirectories under /usr/share/locale. If the locale speci-
fied to the program doesn’t match a locale directory name exactly, then the C
library searches for a match by stripping components from the specified locale in
the following order:
- codeset
- normalized codeset
- territory
- modifier
The normalized codeset is a version of the codeset name in which all nonalphanu-
meric characters are removed, all letters are converted to lowercase, and the result-
ing string is preprended with the characters iso. The aim of normalizing is to
handle variations in the capitalization and punctuation (e.g., extra hyphens) of
codeset names.
As an example of this stripping process, if the locale for a program is specified
as fr_CH.utf-8, but no locale directory by that name exists, then the fr_CH locale
directory will be matched if it exists. If the fr_CH directory doesn’t exist, then the fr
locale directory will be used. In the unlikely event that the fr directory doesn’t
exist, then the setlocale() function, described shortly, will report an error.
The file /usr/share/locale/locale.alias defines alternative ways of specifying
locales to a program. See the locale.aliases(5) manual page for details.