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