[b32e803] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[b06ca36] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[b32e803] | 4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
[d781ffb] | 7 |
|
---|
[f3317d4] | 8 | <sect1 id="ch-scripts-locale">
|
---|
| 9 | <?dbhtml filename="locale.html"?>
|
---|
[d781ffb] | 10 |
|
---|
[f3317d4] | 11 | <title>Configuring the System Locale</title>
|
---|
[d781ffb] | 12 |
|
---|
[f3317d4] | 13 | <indexterm zone="ch-scripts-locale">
|
---|
| 14 | <primary sortas="e-etc-locale-conf">/etc/locale.conf</primary>
|
---|
[d781ffb] | 15 | </indexterm>
|
---|
| 16 |
|
---|
[f3317d4] | 17 | <para>The <filename>/etc/locale.conf</filename> below sets some
|
---|
[d781ffb] | 18 | environment variables necessary for native language support. Setting
|
---|
| 19 | them properly results in:</para>
|
---|
| 20 |
|
---|
| 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>
|
---|
| 40 |
|
---|
[0090db5] | 41 | <para>Replace <replaceable><ll></replaceable> below with the two-letter code
|
---|
[d781ffb] | 42 | for the desired language (e.g., <quote>en</quote>) and
|
---|
[0090db5] | 43 | <replaceable><CC></replaceable> with the two-letter code for the appropriate
|
---|
| 44 | country (e.g., <quote>GB</quote>). <replaceable><charmap></replaceable> should
|
---|
[fa21b3d] | 45 | be replaced with the canonical charmap for your chosen locale. Optional
|
---|
| 46 | modifiers such as <quote>@euro</quote> may also be present.</para>
|
---|
[d781ffb] | 47 |
|
---|
| 48 | <para>The list of all locales supported by Glibc can be obtained by running
|
---|
| 49 | the following command:</para>
|
---|
[81fd230] | 50 |
|
---|
[0ebe9fa4] | 51 | <screen role="nodump"><userinput>locale -a</userinput></screen>
|
---|
[81fd230] | 52 |
|
---|
[fa21b3d] | 53 | <para>Charmaps can have a number of aliases, e.g., <quote>ISO-8859-1</quote>
|
---|
[d781ffb] | 54 | is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
|
---|
[fa21b3d] | 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
|
---|
[0090db5] | 59 | the canonical name, run the following command, where <replaceable><locale
|
---|
| 60 | name></replaceable> is the output given by <command>locale -a</command> for
|
---|
[d781ffb] | 61 | your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
|
---|
[768efb56] | 62 |
|
---|
[0090db5] | 63 | <screen role="nodump"><userinput>LC_ALL=<replaceable><locale name></replaceable> locale charmap</userinput></screen>
|
---|
[768efb56] | 64 |
|
---|
[d781ffb] | 65 | <para>For the <quote>en_GB.iso88591</quote> locale, the above command
|
---|
| 66 | will print:</para>
|
---|
[768efb56] | 67 |
|
---|
[d781ffb] | 68 | <screen><computeroutput>ISO-8859-1</computeroutput></screen>
|
---|
[768efb56] | 69 |
|
---|
[d781ffb] | 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>
|
---|
[c45b780] | 73 |
|
---|
[a85d4b9] | 74 | <screen role="nodump"><userinput>LC_ALL=<locale name> locale language
|
---|
[0090db5] | 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>
|
---|
[c45b780] | 78 |
|
---|
[3db5b78] | 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
|
---|
[d781ffb] | 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 6 or is not supported by
|
---|
| 84 | the default installation of Glibc.</para>
|
---|
[c45b780] | 85 |
|
---|
[ac1d807] | 86 | <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
|
---|
[c45b780] | 87 |
|
---|
[d781ffb] | 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>
|
---|
[c45b780] | 92 |
|
---|
[fa21b3d] | 93 | <!-- FIXME: the xlib example will became obsolete real soon -->
|
---|
[d781ffb] | 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
|
---|
[83f01733] | 96 | following error message if the locale does not exactly match one of the character
|
---|
| 97 | map names in its internal files:</para>
|
---|
[c45b780] | 98 |
|
---|
[ac1d807] | 99 | <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
|
---|
[c45b780] | 100 |
|
---|
[83f01733] | 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>
|
---|
[c45b780] | 108 |
|
---|
[d781ffb] | 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>
|
---|
[768efb56] | 113 |
|
---|
[d781ffb] | 114 | <para>Once the proper locale settings have been determined, create the
|
---|
[f3317d4] | 115 | <filename>/etc/locale.conf</filename> file:</para>
|
---|
[f67f5cf] | 116 |
|
---|
[f3317d4] | 117 | <screen><userinput>cat > /etc/locale.conf << "EOF"
|
---|
| 118 | <literal>LANG=<replaceable><ll>_<CC>.<charmap><@modifiers></replaceable></literal>
|
---|
[b32e803] | 119 | EOF</userinput></screen>
|
---|
| 120 |
|
---|
[fa21b3d] | 121 | <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
|
---|
| 122 | one for United States English users) locales are different. <quote>C</quote>
|
---|
| 123 | uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
|
---|
| 124 | as invalid characters. That's why, e.g., the <command>ls</command> command
|
---|
| 125 | substitutes them with question marks in that locale. Also, an attempt to send
|
---|
| 126 | mail with such characters from Mutt or Pine results in non-RFC-conforming
|
---|
| 127 | messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
|
---|
| 128 | 8-bit</quote>). So you can use the <quote>C</quote> locale only if you are sure that
|
---|
| 129 | you will never need 8-bit characters.</para>
|
---|
| 130 |
|
---|
[ce5ebe1] | 131 | <para>UTF-8 based locales are not supported well by many programs.
|
---|
[b083220f] | 132 | Work is in progress to document and, if possible, fix such problems, see
|
---|
| 133 | <ulink url="&blfs-root;view/svn/introduction/locale-issues.html"/>.</para>
|
---|
[94aa6621] | 134 |
|
---|
[b32e803] | 135 | </sect1>
|
---|