8

Reading

man locale

I figure that that locale displays information about the "current locale" or a list of all available locales.

In addition, running

$ locale

gives...

LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

However, neither the man nor running it actually sheds a light on what these environment variables do. I would like to ask specifically what these environment variables are needed for or used for? (say for example in the context of a software running on this unix/linux OS that has these environment variables)

The Question: What does that mean in the context of a software that is running on the OS with these locales?

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
  • 2
    Locale came about as a system for programatically specifying language, punctuation differences and character encoding in the shell space. It is pure UNIX and pre-dates Mac OS X. On Macs, the shell pulls from the system locale setting that is set by the setup assistant and visible and changeable in the international preference pane – bmike Aug 30 '11 at 16:38
  • bmike, I can't seem to find the user interface on the System Preferences app though. Am currently on Mac 10.6.8 – Calvin Cheng Aug 30 '11 at 17:00
  • It's called language & text on Lion. Just open the system preference app and type language into the top right search field. – bmike Aug 30 '11 at 17:56
  • Possible duplicate of [Explain the effects of export LANG, LC\_CTYPE, LC\_ALL](https://stackoverflow.com/questions/30479607/explain-the-effects-of-export-lang-lc-ctype-lc-all) – kenorb Sep 26 '17 at 13:52

2 Answers2

5

Oh, the man page (man 1 locale) does:

LC_CTYPE
Character classification and case conversion.

LC_COLLATE
Collation order.

LC_TIME
Date and time formats.

LC_NUMERIC
Non-monetary numeric formats.

LC_MONETARY
Monetary formats.

LC_MESSAGES
Formats of informative and diagnostic messages and interactive responses.

Perhaps, you had a look for the 'locale' manpage in the wrong section? These are the standard sections (see man man)

0   Header files (usually found in /usr/include)
1   Executable programs or shell commands
2   System calls (functions provided by the kernel)
3   Library calls (functions within program libraries)
4   Special files (usually found in /dev)
5   File formats and conventions eg /etc/passwd
6   Games
7   Miscellaneous (including macro  packages  and  conven-
    tions), e.g. man(7), groff(7)
8   System administration commands (usually only for root)
9   Kernel routines [Non standard]

so, for the locale binary, you have to look in section 1: man 1 locale. To fully answer your question, I cite the description part of locale's man page:

DESCRIPTION
   The locale utility shall write information  about  the  current  locale
   environment,  or  all  public  locales, to the standard output. For the
   purposes of this section, a public locale is one provided by the imple-
   mentation that is accessible to the application.

   When  locale  is  invoked without any arguments, it shall summarize the
   current locale environment for each locale category  as  determined  by
   the  settings  of the environment variables defined in the Base Defini-
   tions volume of IEEE Std 1003.1-2001, Chapter 7, Locale.

   When invoked with operands,  it  shall  write  values  that  have  been
   assigned to the keywords in the locale categories, as follows:

    * Specifying  a  keyword  name  shall select the named keyword and the
      category containing that keyword.

    * Specifying a category name shall select the named category  and  all
      keywords in that category.

Samples (LC_TIME and LC_MESSAGES):

$ export LC_TIME='fr_FR.UTF-8' #french time
$ date
mar. août 30 18:41:07 CEST 2011
$ export LC_TIME='de_DE.UTF-8' #german time
$ date
Di 30. Aug 18:41:12 CEST 2011 #english time
$ export LC_TIME='en_US.UTF-8'
$ date
Tue Aug 30 18:41:17 CEST 2011
$ rm NON-EXIST
rm: cannot remove `NON-EXIST': No such file or directory
$ export LC_TIME='de_DE.UTF-8' #german time, but english MESSAGES
$ rm NON-EXIST
rm: cannot remove `NON-EXIST': No such file or directory
$ export LC_MESSAGES='de_DE.UTF-8' #german messages
$ rm NON-EXIST
rm: cannot remove `NON-EXIST': Datei oder Verzeichnis nicht gefunden

LC_COLLATE is for sorting information according to a language. LC_MONETARY is the format for currency (US: $1.24, europe: 1.24 €)

Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
0

Locale governs a lot of things, such as:

  1. Encoding in use (i.e., en_US.UTF-8, or some other classic encoding)
  2. Translation files to use for the standard library or other applications.
  3. Internationalization (number formatting, currency, dates)

The C locale is the "default" locale. It is generally advisable to be more specific, and run as something UTF-8 enabled on Linux.

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
  • What does that mean in the context of a software that is running on the OS with these locales? – Calvin Cheng Aug 30 '11 at 16:36
  • 1
    Exactly all of the above. The locale says how the program and standard library are to operate in the presence of different internationalization and localization settings. For instance, with a locale, dates are supposed to be ordered correctly for that locale: M/D/Y, Y/M/D, etc, days of week, whether the decimal separator is `.` or `,` or something else, whether messages should be French or English or Chinese, which character encoding is in use. – Yann Ramin Aug 30 '11 at 16:40
  • Both answers refer to the context. In fact, LOCAL is __part__ of the context. – Dana the Sane Aug 30 '11 at 16:41