3

There are a lot of questions here about how to set these variables but none about how they work.

If I type locale in a terminal it shows me a bunch of variables:

LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"

However, these don't exist on the system. Doing a echo returns blank string echo $LC_MONETARY.

I presume that the utility is reading some database and printing env vars that can be customized and set to override the defaults?

  1. What is the database being read? Can it be edited directly without using these vars to override its settings?
  2. If these vars are set, what system component uses them. Are these used by any user space programs?
  3. Is locale part of a package that comes with other utilities?
  4. Are the variables part of a standard and found on all distros?

Any reference to documentation that explains the LC_ vars and locale utility would be appreciated. Most web articles I found explain how to use these, but not the design/architecture of the locale system.

1 Answers1

3
  1. The values aren’t read from a database. locale applies precedence rules: if LANG is set, it determines the default value for any unset LC_ variable, and if LC_ALL is set, it overrides all values. For example, I have LANG and LC_CTYPE explicitly set to en_GB.UTF-8, and locale shows en_GB.UTF-8 for all values; but if I set LANG to fr_FR.UTF-8, it shows fr_FR.UTF-8 for all values except LC_CTYPE.

  2. The variables are read by the setlocale function, which programs are supposed to call if they care about locales at all.

  3. locale is usually part of the C library.

  4. The variables are defined in POSIX, a standard which defines common interfaces found in most Unix-style systems. Some systems (or rather, C libraries) have extensions; for example the GNU C library defines a number of non-standard locale categories such as LC_ADDRESS.

See also What is the difference between LANG=C and LC_ALL=C? and How does the "locale" program work?

Stephen Kitt
  • 434,908