【问题标题】:What exactly does "locale" do on Mac OS X and/or other Unix/Linux OS“语言环境”在 Mac OS X 和/或其他 Unix/Linux 操作系统上究竟做了什么
【发布时间】:2011-08-30 16:31:17
【问题描述】:

阅读

man locale

我认为该语言环境显示有关“当前语言环境”的信息或所有可用语言环境的列表。

另外,运行

$ locale

给...

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

但是,无论是 man 还是运行它,实际上都没有说明这些环境变量的作用。我想具体问一下这些环境变量需要或用于什么?(例如,在具有这些环境变量的 unix/linux 操作系统上运行的软件的上下文中)

问题:对于在具有这些语言环境的操作系统上运行的软件而言,这意味着什么?

【问题讨论】:

  • Locale 是作为一种在 shell 空间中以编程方式指定语言、标点符号差异和字符编码的系统而出现的。它是纯 UNIX 并且早于 Mac OS X。在 Mac 上,shell 从设置助手设置的系统区域设置中提取,并且在国际首选项窗格中可见和可更改
  • bmike,我似乎无法在系统偏好设置应用程序上找到用户界面。我目前在 Mac 10.6.8
  • Lion 上称为语言和文本。只需打开系统偏好应用程序并在右上角的搜索字段中输入语言即可。

标签: linux macos locale


【解决方案1】:

哦,手册页 (man 1 locale) 可以:

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.

也许,您在错误的部分中查找了“语言环境”联机帮助页?这些是标准部分(参见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]

所以,对于locale 二进制文件,您必须查看1 部分:man 1 locale。为了完全回答您的问题,我引用了语言环境手册页的描述部分:

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.

样本(LC_TIME 和 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 用于根据语言对信息进行排序。 LC_MONETARY 是货币格式(美国:$1.24,欧洲:1.24 €)

【讨论】:

  • 在具有这些语言环境的操作系统上运行的软件的上下文中,这意味着什么?
【解决方案2】:

Locale 管理着很多事情,例如:

  1. 正在使用的编码(即en_US.UTF-8,或其他一些经典编码)
  2. 用于标准库或其他应用程序的翻译文件。
  3. 国际化(数字格式、货币、日期)

C 区域设置是“默认”区域设置。通常建议更具体一些,并在 Linux 上以启用 UTF-8 的方式运行。

【讨论】:

  • 在具有这些语言环境的操作系统上运行的软件的上下文中,这意味着什么?
  • 正是以上所有。语言环境说明程序和标准库在存在不同国际化和本地化设置的情况下如何运行。例如,对于一个语言环境,应该为该语言环境正确排序日期:M/D/Y、Y/M/D 等、星期几、小数点分隔符是 . 或 , 还是什么否则,消息应该是法语还是英语还是中文,使用哪种字符编码。
  • 两个答案都指上下文。事实上,LOCAL 是上下文的一部分。
猜你喜欢
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-23
  • 2012-07-23
  • 2016-09-10
相关资源
最近更新 更多