locale.xml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-scripts-locale" revision="systemd">
  8. <?dbhtml filename="locale.html"?>
  9. <title>Configuring the System Locale</title>
  10. <indexterm zone="ch-scripts-locale">
  11. <primary sortas="e-etc-locale-conf">/etc/locale.conf</primary>
  12. </indexterm>
  13. <para>The <filename>/etc/locale.conf</filename> below sets some
  14. environment variables necessary for native language support. Setting
  15. them properly results in:</para>
  16. <itemizedlist>
  17. <listitem>
  18. <para>The output of programs translated into the native language</para>
  19. </listitem>
  20. <listitem>
  21. <para>Correct classification of characters into letters, digits and other
  22. classes. This is necessary for <command>bash</command> to properly accept
  23. non-ASCII characters in command lines in non-English locales</para>
  24. </listitem>
  25. <listitem>
  26. <para>The correct alphabetical sorting order for the country</para>
  27. </listitem>
  28. <listitem>
  29. <para>Appropriate default paper size</para>
  30. </listitem>
  31. <listitem>
  32. <para>Correct formatting of monetary, time, and date values</para>
  33. </listitem>
  34. </itemizedlist>
  35. <para>Replace <replaceable>&lt;ll&gt;</replaceable> below with the two-letter code
  36. for the desired language (e.g., <quote>en</quote>) and
  37. <replaceable>&lt;CC&gt;</replaceable> with the two-letter code for the appropriate
  38. country (e.g., <quote>GB</quote>). <replaceable>&lt;charmap&gt;</replaceable> should
  39. be replaced with the canonical charmap for your chosen locale. Optional
  40. modifiers such as <quote>@euro</quote> may also be present.</para>
  41. <para>The list of all locales supported by Glibc can be obtained by running
  42. the following command:</para>
  43. <screen role="nodump"><userinput>locale -a</userinput></screen>
  44. <para>Charmaps can have a number of aliases, e.g., <quote>ISO-8859-1</quote>
  45. is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
  46. Some applications cannot handle the various synonyms correctly (e.g., require
  47. that <quote>UTF-8</quote> is written as <quote>UTF-8</quote>, not
  48. <quote>utf8</quote>), so it is safest in most
  49. cases to choose the canonical name for a particular locale. To determine
  50. the canonical name, run the following command, where <replaceable>&lt;locale
  51. name&gt;</replaceable> is the output given by <command>locale -a</command> for
  52. your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
  53. <screen role="nodump"><userinput>LC_ALL=<replaceable>&lt;locale name&gt;</replaceable> locale charmap</userinput></screen>
  54. <para>For the <quote>en_GB.iso88591</quote> locale, the above command
  55. will print:</para>
  56. <screen><computeroutput>ISO-8859-1</computeroutput></screen>
  57. <para>This results in a final locale setting of <quote>en_GB.ISO-8859-1</quote>.
  58. It is important that the locale found using the heuristic above is tested prior
  59. to it being added to the Bash startup files:</para>
  60. <screen role="nodump"><userinput>LC_ALL=&lt;locale name&gt; locale language
  61. LC_ALL=&lt;locale name&gt; locale charmap
  62. LC_ALL=&lt;locale name&gt; locale int_curr_symbol
  63. LC_ALL=&lt;locale name&gt; locale int_prefix</userinput></screen>
  64. <para>The above commands should print the language name, the character
  65. encoding used by the locale, the local currency, and the prefix to dial
  66. before the telephone number in order to get into the country. If any of the
  67. commands above fail with a message similar to the one shown below, this means
  68. that your locale was either not installed in Chapter&nbsp;6 or is not supported by
  69. the default installation of Glibc.</para>
  70. <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
  71. <para>If this happens, you should either install the desired locale using the
  72. <command>localedef</command> command, or consider choosing a different locale.
  73. Further instructions assume that there are no such error messages from
  74. Glibc.</para>
  75. <!-- FIXME: the xlib example will became obsolete real soon -->
  76. <para>Some packages beyond LFS may also lack support for your chosen locale. One
  77. example is the X library (part of the X Window System), which outputs the
  78. following error message if the locale does not exactly match one of the character
  79. map names in its internal files:</para>
  80. <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
  81. <para>In several cases Xlib expects that the character map will be listed in
  82. uppercase notation with canonical dashes. For instance, "ISO-8859-1" rather
  83. than "iso88591". It is also possible to find an appropriate specification by
  84. removing the charmap part of the locale specification. This can be checked
  85. by running the <command>locale charmap</command> command in both locales.
  86. For example, one would have to change "de_DE.ISO-8859-15@euro" to
  87. "de_DE@euro" in order to get this locale recognized by Xlib.</para>
  88. <para>Other packages can also function incorrectly (but may not necessarily
  89. display any error messages) if the locale name does not meet their expectations.
  90. In those cases, investigating how other Linux distributions support your locale
  91. might provide some useful information.</para>
  92. <para>Once the proper locale settings have been determined, create the
  93. <filename>/etc/locale.conf</filename> file:</para>
  94. <screen><userinput>cat &gt; /etc/locale.conf &lt;&lt; "EOF"
  95. <literal>LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable></literal>
  96. EOF</userinput></screen>
  97. <para>Note that you can modify <filename>/etc/locale.conf</filename> with the
  98. systemd <command>localectl</command> utility. To use
  99. <command>localectl</command> for the example above, run:</para>
  100. <screen role="nodump"><userinput>localectl set-locale LANG="<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>"</userinput></screen>
  101. <para>You can also specify other language specific environment variables such
  102. as <envar>LANG</envar>, <envar>LC_CTYPE</envar>, <envar>LC_NUMERIC</envar> or
  103. any other environment variable from <command>locale</command> output. Just
  104. separate them with a space. An example where <envar>LANG</envar> is set as
  105. en_US.UTF-8 but <envar>LC_CTYPE</envar> is set as just en_US is:</para>
  106. <screen role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
  107. <note><para>Please note that the <command>localectl</command> command can
  108. be used only on a system booted with systemd.</para></note>
  109. <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
  110. one for United States English users) locales are different. <quote>C</quote>
  111. uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
  112. as invalid characters. That's why, e.g., the <command>ls</command> command
  113. substitutes them with question marks in that locale. Also, an attempt to send
  114. mail with such characters from Mutt or Pine results in non-RFC-conforming
  115. messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
  116. 8-bit</quote>). So you can use the <quote>C</quote> locale only if you are sure that
  117. you will never need 8-bit characters.</para>
  118. <para>UTF-8 based locales are not supported well by many programs.
  119. Work is in progress to document and, if possible, fix such problems, see
  120. <ulink url="&blfs-book;introduction/locale-issues.html"/>.</para>
  121. </sect1>