This answer attempts to directly quote relevant standards and contains no speculation or inaccurate statements. Edits and corrections welcome as long as they cite relevant standards and authoritative sources.
Environment Variable Priority
The priority of all four variables LC_ALL
, LC_*
, LANG
, and LANGUAGE
according to applicable standards:
man 7 local
:
If the second argument to setlocale(3) is an empty string, "", for the
default locale, it is determined using the following steps:
If there is a non-null environment variable LC_ALL, the value of
LC_ALL is used.
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.
If there is a non-null environment variable LANG, the value of LANG
is used.
- Gnu Gettext Manual:
When a program looks up locale dependent values, it does this according to the following environment variables, in priority order:
- LANGUAGE
- LC_ALL
- LC_xxx, according to selected locale category: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, ...
- LANG
So the currently accepted answer is inaccurate.
Environment Variable Format
From another part of the Gnu Gettext Manual:
A locale name usually has the form ‘ll_CC’. Here ‘ll’ is an ISO 639 two-letter language code, and ‘CC’ is an ISO 3166 two-letter country code.
Many locale names have an extended syntax ‘ll_CC.encoding’ that also specifies the character encoding.
Some locale names use ‘ll_CC@variant’ instead of ‘ll_CC’. The ‘@variant’ can denote any kind of characteristics that is not already implied by the language ll and the country CC.