[7152faa] | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
[1118b17] | 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 |
|
---|
[afcfd74] | 8 | <sect1 id="ch-config-locale" revision="systemd">
|
---|
[1118b17] | 9 | <?dbhtml filename="locale.html"?>
|
---|
| 10 |
|
---|
| 11 | <title>Configuring the System Locale</title>
|
---|
| 12 |
|
---|
[afcfd74] | 13 | <indexterm zone="ch-config-locale">
|
---|
[1118b17] | 14 | <primary sortas="e-etc-locale-conf">/etc/locale.conf</primary>
|
---|
| 15 | </indexterm>
|
---|
| 16 |
|
---|
[9e7475a] | 17 | <para>The <filename>/etc/locale.conf</filename> file below sets some
|
---|
[1118b17] | 18 | environment variables necessary for native language support. Setting
|
---|
| 19 | them properly results in:</para>
|
---|
| 20 |
|
---|
| 21 | <itemizedlist>
|
---|
| 22 | <listitem>
|
---|
[9e7475a] | 23 | <para>The output of programs being translated into your native language</para>
|
---|
[1118b17] | 24 | </listitem>
|
---|
| 25 | <listitem>
|
---|
[9e7475a] | 26 | <para>The correct classification of characters into letters, digits and other
|
---|
[1118b17] | 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>
|
---|
[9e7475a] | 34 | <para>The appropriate default paper size</para>
|
---|
[1118b17] | 35 | </listitem>
|
---|
| 36 | <listitem>
|
---|
[9e7475a] | 37 | <para>The correct formatting of monetary, time, and date values</para>
|
---|
[1118b17] | 38 | </listitem>
|
---|
| 39 | </itemizedlist>
|
---|
| 40 |
|
---|
| 41 | <para>Replace <replaceable><ll></replaceable> below with the two-letter code
|
---|
[360fdfca] | 42 | for your desired language (e.g., <literal>en</literal>) and
|
---|
[1118b17] | 43 | <replaceable><CC></replaceable> with the two-letter code for the appropriate
|
---|
[360fdfca] | 44 | country (e.g., <literal>GB</literal>). <replaceable><charmap></replaceable> should
|
---|
[1118b17] | 45 | be replaced with the canonical charmap for your chosen locale. Optional
|
---|
[360fdfca] | 46 | modifiers such as <literal>@euro</literal> may also be present.</para>
|
---|
[1118b17] | 47 |
|
---|
| 48 | <para>The list of all locales supported by Glibc can be obtained by running
|
---|
| 49 | the following command:</para>
|
---|
| 50 |
|
---|
| 51 | <screen role="nodump"><userinput>locale -a</userinput></screen>
|
---|
| 52 |
|
---|
| 53 | <para>Charmaps can have a number of aliases, e.g., <quote>ISO-8859-1</quote>
|
---|
[360fdfca] | 54 | is also referred to as <quote>iso8859-1</quote> and <quote>iso88591.</quote>
|
---|
[1118b17] | 55 | Some applications cannot handle the various synonyms correctly (e.g., require
|
---|
[360fdfca] | 56 | that <quote>UTF-8</quote> is written as <literal>UTF-8,</literal> not
|
---|
| 57 | <literal>utf8</literal>), so it is the safest in most
|
---|
[1118b17] | 58 | cases to choose the canonical name for a particular locale. To determine
|
---|
| 59 | the canonical name, run the following command, where <replaceable><locale
|
---|
| 60 | name></replaceable> is the output given by <command>locale -a</command> for
|
---|
| 61 | your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
|
---|
| 62 |
|
---|
| 63 | <screen role="nodump"><userinput>LC_ALL=<replaceable><locale name></replaceable> locale charmap</userinput></screen>
|
---|
| 64 |
|
---|
| 65 | <para>For the <quote>en_GB.iso88591</quote> locale, the above command
|
---|
| 66 | will print:</para>
|
---|
| 67 |
|
---|
| 68 | <screen><computeroutput>ISO-8859-1</computeroutput></screen>
|
---|
| 69 |
|
---|
[360fdfca] | 70 | <para>This results in a final locale setting of <literal>en_GB.ISO-8859-1</literal>.
|
---|
[1118b17] | 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>
|
---|
| 73 |
|
---|
| 74 | <screen role="nodump"><userinput>LC_ALL=<locale name> locale language
|
---|
| 75 | LC_ALL=<locale name> locale charmap
|
---|
| 76 | LC_ALL=<locale name> locale int_curr_symbol
|
---|
| 77 | LC_ALL=<locale name> locale int_prefix</userinput></screen>
|
---|
| 78 |
|
---|
| 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
|
---|
[c34b4fb] | 83 | that your locale was either not installed in Chapter 8 or is not
|
---|
[9e7475a] | 84 | supported by the default installation of Glibc.</para>
|
---|
[1118b17] | 85 |
|
---|
| 86 | <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
|
---|
| 87 |
|
---|
| 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>
|
---|
| 92 |
|
---|
| 93 | <para>Other packages can also function incorrectly (but may not necessarily
|
---|
| 94 | display any error messages) if the locale name does not meet their expectations.
|
---|
| 95 | In those cases, investigating how other Linux distributions support your locale
|
---|
| 96 | might provide some useful information.</para>
|
---|
| 97 |
|
---|
| 98 | <para>Once the proper locale settings have been determined, create the
|
---|
| 99 | <filename>/etc/locale.conf</filename> file:</para>
|
---|
| 100 |
|
---|
| 101 | <screen><userinput>cat > /etc/locale.conf << "EOF"
|
---|
| 102 | <literal>LANG=<replaceable><ll>_<CC>.<charmap><@modifiers></replaceable></literal>
|
---|
| 103 | EOF</userinput></screen>
|
---|
| 104 |
|
---|
[0d84af1] | 105 | <para>Note that you can modify <filename>/etc/locale.conf</filename> with the
|
---|
| 106 | systemd <command>localectl</command> utility. To use
|
---|
| 107 | <command>localectl</command> for the example above, run:</para>
|
---|
[1118b17] | 108 |
|
---|
| 109 | <screen role="nodump"><userinput>localectl set-locale LANG="<replaceable><ll>_<CC>.<charmap><@modifiers></replaceable>"</userinput></screen>
|
---|
| 110 |
|
---|
| 111 | <para>You can also specify other language specific environment variables such
|
---|
| 112 | as <envar>LANG</envar>, <envar>LC_CTYPE</envar>, <envar>LC_NUMERIC</envar> or
|
---|
| 113 | any other environment variable from <command>locale</command> output. Just
|
---|
| 114 | separate them with a space. An example where <envar>LANG</envar> is set as
|
---|
| 115 | en_US.UTF-8 but <envar>LC_CTYPE</envar> is set as just en_US is:</para>
|
---|
| 116 |
|
---|
| 117 | <screen role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
|
---|
| 118 |
|
---|
[4f560248] | 119 | <note><para>Please note that the <command>localectl</command> command
|
---|
| 120 | doesn't work in the chroot environment. It can only
|
---|
| 121 | be used after the LFS system is booted with systemd.</para></note>
|
---|
[1118b17] | 122 |
|
---|
| 123 | <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
|
---|
| 124 | one for United States English users) locales are different. <quote>C</quote>
|
---|
| 125 | uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
|
---|
| 126 | as invalid characters. That's why, e.g., the <command>ls</command> command
|
---|
| 127 | substitutes them with question marks in that locale. Also, an attempt to send
|
---|
| 128 | mail with such characters from Mutt or Pine results in non-RFC-conforming
|
---|
| 129 | messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
|
---|
[c34b4fb] | 130 | 8-bit</quote>). It's suggested that you use the <quote>C</quote> locale only
|
---|
[9e7475a] | 131 | if you are certain that you will never need 8-bit characters.</para>
|
---|
[1118b17] | 132 |
|
---|
[9e7475a] | 133 | <!--
|
---|
[1118b17] | 134 | <para>UTF-8 based locales are not supported well by many programs.
|
---|
| 135 | Work is in progress to document and, if possible, fix such problems, see
|
---|
| 136 | <ulink url="&blfs-book;introduction/locale-issues.html"/>.</para>
|
---|
[9e7475a] | 137 | -->
|
---|
[1118b17] | 138 |
|
---|
| 139 | </sect1>
|
---|