[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 |
|
---|
[6ebb3b9] | 8 | <sect1 id="ch-config-locale">
|
---|
[1118b17] | 9 | <?dbhtml filename="locale.html"?>
|
---|
| 10 |
|
---|
| 11 | <title>Configuring the System Locale</title>
|
---|
| 12 |
|
---|
[afcfd74] | 13 | <indexterm zone="ch-config-locale">
|
---|
[6ebb3b9] | 14 | <primary sortas="e-/etc/profile">/etc/profile</primary>
|
---|
[1118b17] | 15 | </indexterm>
|
---|
| 16 |
|
---|
[6ebb3b9] | 17 | <indexterm zone="ch-config-locale" revision='systemd'>
|
---|
| 18 | <primary sortas="e-/etc/profile">/etc/locale.conf</primary>
|
---|
| 19 | </indexterm>
|
---|
| 20 |
|
---|
| 21 | <para>Some environment variables are necessary for native language
|
---|
| 22 | support. Setting them properly results in:</para>
|
---|
[1118b17] | 23 |
|
---|
| 24 | <itemizedlist>
|
---|
| 25 | <listitem>
|
---|
[9e7475a] | 26 | <para>The output of programs being translated into your native language</para>
|
---|
[1118b17] | 27 | </listitem>
|
---|
| 28 | <listitem>
|
---|
[9e7475a] | 29 | <para>The correct classification of characters into letters, digits and other
|
---|
[1118b17] | 30 | classes. This is necessary for <command>bash</command> to properly accept
|
---|
| 31 | non-ASCII characters in command lines in non-English locales</para>
|
---|
| 32 | </listitem>
|
---|
| 33 | <listitem>
|
---|
| 34 | <para>The correct alphabetical sorting order for the country</para>
|
---|
| 35 | </listitem>
|
---|
| 36 | <listitem>
|
---|
[9e7475a] | 37 | <para>The appropriate default paper size</para>
|
---|
[1118b17] | 38 | </listitem>
|
---|
| 39 | <listitem>
|
---|
[9e7475a] | 40 | <para>The correct formatting of monetary, time, and date values</para>
|
---|
[1118b17] | 41 | </listitem>
|
---|
| 42 | </itemizedlist>
|
---|
| 43 |
|
---|
| 44 | <para>Replace <replaceable><ll></replaceable> below with the two-letter code
|
---|
[360fdfca] | 45 | for your desired language (e.g., <literal>en</literal>) and
|
---|
[1118b17] | 46 | <replaceable><CC></replaceable> with the two-letter code for the appropriate
|
---|
[360fdfca] | 47 | country (e.g., <literal>GB</literal>). <replaceable><charmap></replaceable> should
|
---|
[1118b17] | 48 | be replaced with the canonical charmap for your chosen locale. Optional
|
---|
[360fdfca] | 49 | modifiers such as <literal>@euro</literal> may also be present.</para>
|
---|
[1118b17] | 50 |
|
---|
| 51 | <para>The list of all locales supported by Glibc can be obtained by running
|
---|
| 52 | the following command:</para>
|
---|
| 53 |
|
---|
| 54 | <screen role="nodump"><userinput>locale -a</userinput></screen>
|
---|
| 55 |
|
---|
[8497448] | 56 | <para>Charmaps can have a number of aliases, e.g.,
|
---|
| 57 | <literal>ISO-8859-1</literal> is also referred to as
|
---|
| 58 | <literal>iso8859-1</literal> and <literal>iso88591</literal>.
|
---|
[1118b17] | 59 | Some applications cannot handle the various synonyms correctly (e.g., require
|
---|
[8497448] | 60 | that <literal>UTF-8</literal> is written as <literal>UTF-8</literal>, not
|
---|
[360fdfca] | 61 | <literal>utf8</literal>), so it is the safest in most
|
---|
[1118b17] | 62 | cases to choose the canonical name for a particular locale. To determine
|
---|
| 63 | the canonical name, run the following command, where <replaceable><locale
|
---|
| 64 | name></replaceable> is the output given by <command>locale -a</command> for
|
---|
[8497448] | 65 | your preferred locale (<literal>en_GB.iso88591</literal> in our
|
---|
| 66 | example).</para>
|
---|
[1118b17] | 67 |
|
---|
| 68 | <screen role="nodump"><userinput>LC_ALL=<replaceable><locale name></replaceable> locale charmap</userinput></screen>
|
---|
| 69 |
|
---|
[8497448] | 70 | <para>For the <literal>en_GB.iso88591</literal> locale, the above command
|
---|
[1118b17] | 71 | will print:</para>
|
---|
| 72 |
|
---|
| 73 | <screen><computeroutput>ISO-8859-1</computeroutput></screen>
|
---|
| 74 |
|
---|
[360fdfca] | 75 | <para>This results in a final locale setting of <literal>en_GB.ISO-8859-1</literal>.
|
---|
[1118b17] | 76 | It is important that the locale found using the heuristic above is tested prior
|
---|
| 77 | to it being added to the Bash startup files:</para>
|
---|
| 78 |
|
---|
| 79 | <screen role="nodump"><userinput>LC_ALL=<locale name> locale language
|
---|
| 80 | LC_ALL=<locale name> locale charmap
|
---|
| 81 | LC_ALL=<locale name> locale int_curr_symbol
|
---|
| 82 | LC_ALL=<locale name> locale int_prefix</userinput></screen>
|
---|
| 83 |
|
---|
| 84 | <para>The above commands should print the language name, the character
|
---|
| 85 | encoding used by the locale, the local currency, and the prefix to dial
|
---|
| 86 | before the telephone number in order to get into the country. If any of the
|
---|
| 87 | commands above fail with a message similar to the one shown below, this means
|
---|
[c34b4fb] | 88 | that your locale was either not installed in Chapter 8 or is not
|
---|
[9e7475a] | 89 | supported by the default installation of Glibc.</para>
|
---|
[1118b17] | 90 |
|
---|
| 91 | <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
|
---|
| 92 |
|
---|
| 93 | <para>If this happens, you should either install the desired locale using the
|
---|
| 94 | <command>localedef</command> command, or consider choosing a different locale.
|
---|
| 95 | Further instructions assume that there are no such error messages from
|
---|
| 96 | Glibc.</para>
|
---|
| 97 |
|
---|
| 98 | <para>Other packages can also function incorrectly (but may not necessarily
|
---|
| 99 | display any error messages) if the locale name does not meet their expectations.
|
---|
| 100 | In those cases, investigating how other Linux distributions support your locale
|
---|
| 101 | might provide some useful information.</para>
|
---|
| 102 |
|
---|
[6ebb3b9] | 103 | <para revision='systemd'>Once the proper locale settings have been
|
---|
| 104 | determined, create the <filename>/etc/locale.conf</filename> file:</para>
|
---|
[1118b17] | 105 |
|
---|
[6ebb3b9] | 106 | <screen revision='systemd'><userinput>cat > /etc/locale.conf << "EOF"
|
---|
[1118b17] | 107 | <literal>LANG=<replaceable><ll>_<CC>.<charmap><@modifiers></replaceable></literal>
|
---|
| 108 | EOF</userinput></screen>
|
---|
| 109 |
|
---|
[6ebb3b9] | 110 | <para>The shell program <command>/bin/bash</command> (here after referred
|
---|
| 111 | as <quote>the shell</quote>) uses a collection of startup files to help
|
---|
| 112 | create the environment to run in. Each file has a specific use and may
|
---|
| 113 | affect login and interactive environments differently. The files in the
|
---|
| 114 | <filename class="directory">/etc</filename> directory provide global
|
---|
| 115 | settings. If equivalent files exist in the home directory, they
|
---|
| 116 | may override the global settings.</para>
|
---|
| 117 |
|
---|
| 118 | <para>An interactive login shell is started after a successful login,
|
---|
| 119 | using <command>/bin/login</command>, by reading the
|
---|
| 120 | <filename>/etc/passwd</filename> file. An interactive non-login shell is
|
---|
| 121 | started at the command-line (e.g.
|
---|
| 122 | <prompt>[prompt]$</prompt><command>/bin/bash</command>). A
|
---|
| 123 | non-interactive shell is usually present when a shell script is running.
|
---|
| 124 | It is non-interactive because it is processing a script and not waiting
|
---|
| 125 | for user input between commands.</para>
|
---|
| 126 |
|
---|
| 127 | <para><phrase revision='systemd'>The login shells are often unaffected by
|
---|
| 128 | the settings in <filename>/etc/locale.conf</filename>. </phrase>Create the
|
---|
| 129 | <filename>/etc/profile</filename>
|
---|
| 130 | <phrase revision='sysv'>once the proper locale settings have been
|
---|
| 131 | determined to set the desired locale</phrase><phrase
|
---|
| 132 | revision='systemd'>to read the locale settings from
|
---|
| 133 | <filename>/etc/locale.conf</filename> and export them</phrase>,
|
---|
[4ecfc55] | 134 | but set the <literal>C.UTF-8</literal> locale instead if running in the Linux
|
---|
[6ebb3b9] | 135 | console (to prevent programs from outputting characters that the Linux
|
---|
| 136 | console is unable to render):</para>
|
---|
| 137 |
|
---|
| 138 | <screen revision="systemd"><userinput>cat > /etc/profile << "EOF"
|
---|
| 139 | <literal># Begin /etc/profile
|
---|
| 140 |
|
---|
| 141 | for i in $(locale); do
|
---|
| 142 | unset ${i%=*}
|
---|
| 143 | done
|
---|
| 144 |
|
---|
| 145 | if [[ "$TERM" = linux ]]; then
|
---|
[4ecfc55] | 146 | export LANG=C.UTF-8
|
---|
[6ebb3b9] | 147 | else
|
---|
| 148 | source /etc/locale.conf
|
---|
| 149 |
|
---|
| 150 | for i in $(locale); do
|
---|
| 151 | key=${i%=*}
|
---|
| 152 | if [[ -v $key ]]; then
|
---|
| 153 | export $key
|
---|
| 154 | fi
|
---|
| 155 | done
|
---|
| 156 | fi
|
---|
| 157 |
|
---|
| 158 | # End /etc/profile</literal>
|
---|
| 159 | EOF</userinput></screen>
|
---|
| 160 |
|
---|
| 161 | <screen revision="sysv"><userinput>cat > /etc/profile << "EOF"
|
---|
| 162 | <literal># Begin /etc/profile
|
---|
| 163 |
|
---|
| 164 | for i in $(locale); do
|
---|
| 165 | unset ${i%=*}
|
---|
| 166 | done
|
---|
| 167 |
|
---|
| 168 | if [[ "$TERM" = linux ]]; then
|
---|
[4ecfc55] | 169 | export LANG=C.UTF-8
|
---|
[6ebb3b9] | 170 | else
|
---|
| 171 | export LANG=<replaceable><ll>_<CC>.<charmap><@modifiers></replaceable>
|
---|
| 172 | fi
|
---|
| 173 |
|
---|
| 174 | # End /etc/profile</literal>
|
---|
| 175 | EOF</userinput></screen>
|
---|
| 176 |
|
---|
| 177 | <para revision='systemd'>Note that you can modify <filename>/etc/locale.conf</filename> with the
|
---|
[0d84af1] | 178 | systemd <command>localectl</command> utility. To use
|
---|
| 179 | <command>localectl</command> for the example above, run:</para>
|
---|
[1118b17] | 180 |
|
---|
[6ebb3b9] | 181 | <screen revision='systemd' role="nodump"><userinput>localectl set-locale LANG="<replaceable><ll>_<CC>.<charmap><@modifiers></replaceable>"</userinput></screen>
|
---|
[1118b17] | 182 |
|
---|
[6ebb3b9] | 183 | <para revision='systemd'>You can also specify other language specific
|
---|
| 184 | environment variables such as <envar>LANG</envar>,
|
---|
| 185 | <envar>LC_CTYPE</envar>, <envar>LC_NUMERIC</envar> or any other
|
---|
| 186 | environment variable from <command>locale</command> output. Just separate
|
---|
| 187 | them with a space. An example where <envar>LANG</envar> is set as
|
---|
[1118b17] | 188 | en_US.UTF-8 but <envar>LC_CTYPE</envar> is set as just en_US is:</para>
|
---|
| 189 |
|
---|
[6ebb3b9] | 190 | <screen revision='systemd' role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
|
---|
[1118b17] | 191 |
|
---|
[6ebb3b9] | 192 | <note revision='systemd'><para>Please note that the
|
---|
| 193 | <command>localectl</command> command doesn't work in the chroot
|
---|
| 194 | environment. It can only be used after the LFS system is booted with
|
---|
| 195 | systemd.</para></note>
|
---|
[1118b17] | 196 |
|
---|
[8497448] | 197 | <para>The <literal>C</literal> (default) and <literal>en_US</literal>
|
---|
| 198 | (the recommended one for United States English users) locales are
|
---|
| 199 | different. <literal>C</literal>
|
---|
[1118b17] | 200 | uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
|
---|
| 201 | as invalid characters. That's why, e.g., the <command>ls</command> command
|
---|
| 202 | substitutes them with question marks in that locale. Also, an attempt to send
|
---|
| 203 | mail with such characters from Mutt or Pine results in non-RFC-conforming
|
---|
[8497448] | 204 | messages being sent (the charset in the outgoing mail is indicated as
|
---|
| 205 | <computeroutput>unknown 8-bit</computeroutput>). It's suggested that you
|
---|
| 206 | use the <literal>C</literal> locale only
|
---|
[9e7475a] | 207 | if you are certain that you will never need 8-bit characters.</para>
|
---|
[1118b17] | 208 |
|
---|
| 209 | </sect1>
|
---|