[73e1db21] | 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 |
|
---|
| 8 | <sect1 id="ch-scripts-locale">
|
---|
| 9 | <title>Setting Up Locale Information</title>
|
---|
| 10 | <?dbhtml filename="locale.html"?>
|
---|
| 11 |
|
---|
| 12 | <indexterm zone="ch-scripts-locale">
|
---|
[2164942] | 13 | <primary sortas="e-/etc/locale.conf">/etc/locale.conf</primary>
|
---|
[73e1db21] | 14 | </indexterm>
|
---|
| 15 |
|
---|
[6365b5d] | 16 | <para>The <filename>/etc/locale.conf</filename> below sets some environment
|
---|
| 17 | variables necessary for native language support. Setting them properly
|
---|
| 18 | results in:</para>
|
---|
[73e1db21] | 19 |
|
---|
| 20 | <itemizedlist>
|
---|
| 21 | <listitem>
|
---|
| 22 | <para>The output of programs translated into the native language</para>
|
---|
| 23 | </listitem>
|
---|
| 24 | <listitem>
|
---|
[6365b5d] | 25 | <para>Correct classification of characters into letters, digits and other
|
---|
| 26 | classes. This is necessary for <command>bash</command> to properly accept
|
---|
| 27 | non-ASCII characters in command lines in non-English locales</para>
|
---|
[73e1db21] | 28 | </listitem>
|
---|
| 29 | <listitem>
|
---|
| 30 | <para>The correct alphabetical sorting order for the country</para>
|
---|
| 31 | </listitem>
|
---|
| 32 | <listitem>
|
---|
| 33 | <para>Appropriate default paper size</para>
|
---|
| 34 | </listitem>
|
---|
| 35 | <listitem>
|
---|
| 36 | <para>Correct formatting of monetary, time, and date values</para>
|
---|
| 37 | </listitem>
|
---|
| 38 | </itemizedlist>
|
---|
| 39 |
|
---|
| 40 | <para>Replace <replaceable>[ll]</replaceable> below with the
|
---|
| 41 | two-letter code for the desired language (e.g., <quote>en</quote>) and
|
---|
| 42 | <replaceable>[CC]</replaceable> with the two-letter code for the
|
---|
[2164942] | 43 | appropriate country (e.g., <quote>GB</quote> or <quote>US</quote>).
|
---|
[73e1db21] | 44 | <replaceable>[charmap]</replaceable> should be replaced with the
|
---|
[6365b5d] | 45 | canonical charmap for your chosen locale. Optional modifiers such as
|
---|
| 46 | <quote>@euro</quote> may also be present.</para>
|
---|
[73e1db21] | 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>Locales can have a number of synonyms, 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, so it is
|
---|
| 56 | safest to choose the canonical name for a particular locale. To determine
|
---|
| 57 | the canonical name, run the following command, where <replaceable>[locale
|
---|
| 58 | name]</replaceable> is the output given by <command>locale -a</command> for
|
---|
| 59 | your preferred locale (<quote>en_US.utf8</quote> in our example).</para>
|
---|
| 60 |
|
---|
| 61 | <screen role="nodump"><userinput>LC_ALL=<replaceable>[locale name]</replaceable> locale charmap</userinput></screen>
|
---|
| 62 |
|
---|
| 63 | <para>For the <quote>en_US.utf8</quote> locale, the above command
|
---|
| 64 | will print:</para>
|
---|
| 65 |
|
---|
| 66 | <screen><computeroutput>UTF-8</computeroutput></screen>
|
---|
| 67 |
|
---|
| 68 | <para>This results in a final locale setting of <quote>en_US.UTF-8</quote>.
|
---|
[6365b5d] | 69 | It is important that the locale found using the heuristic above is tested
|
---|
| 70 | prior to it being added to <filename>/etc/locale.conf</filename>:</para>
|
---|
[73e1db21] | 71 |
|
---|
[24b004c] | 72 | <screen role="nodump"><userinput>LC_ALL=[locale name] locale territory
|
---|
[73e1db21] | 73 | LC_ALL=[locale name] locale language
|
---|
| 74 | LC_ALL=[locale name] locale charmap
|
---|
| 75 | LC_ALL=[locale name] locale int_curr_symbol
|
---|
| 76 | LC_ALL=[locale name] locale int_prefix</userinput></screen>
|
---|
| 77 |
|
---|
| 78 | <para>The above commands should print the language name, the character
|
---|
| 79 | encoding used by the locale, the local currency, and the prefix to dial
|
---|
| 80 | before the telephone number in order to get into the country. If any of the
|
---|
| 81 | commands above fail with a message similar to the one shown below, this means
|
---|
| 82 | that your locale was either not installed in Chapter 10 or is not supported by
|
---|
| 83 | the default installation of Glibc.</para>
|
---|
| 84 |
|
---|
| 85 | <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
|
---|
| 86 |
|
---|
| 87 | <para>If this happens, you should either install the desired locale using
|
---|
| 88 | the <command>localedef</command> command, or consider choosing a different
|
---|
| 89 | locale. Further instructions assume that there are no such error messages
|
---|
| 90 | from Glibc.</para>
|
---|
| 91 |
|
---|
| 92 | <para>Some packages beyond CLFS may also lack support for your chosen locale.
|
---|
| 93 | One example is the X library (part of the X Window System), which outputs
|
---|
| 94 | the following error message:</para>
|
---|
| 95 |
|
---|
| 96 | <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
|
---|
| 97 |
|
---|
| 98 | <para>Sometimes it is possible to fix this by removing the charmap part of
|
---|
| 99 | the locale specification, as long as that does not change the character map
|
---|
| 100 | that Glibc associates with the locale (this can be checked by running the
|
---|
| 101 | <command>locale charmap</command> command in both locales). For example,
|
---|
| 102 | one would have to change "de_DE.ISO-8859-15@euro" to
|
---|
| 103 | "de_DE@euro" in order to get this locale recognized by Xlib.</para>
|
---|
| 104 |
|
---|
| 105 | <para>Other packages can also function incorrectly (but may not necessarily
|
---|
[6365b5d] | 106 | display any error messages) if the locale name does not meet their
|
---|
| 107 | expectations. In those cases, investigating how other Linux distributions
|
---|
| 108 | support your locale might provide some useful information.</para>
|
---|
[73e1db21] | 109 |
|
---|
| 110 | <para>Once the proper locale settings have been determined, create the
|
---|
[2164942] | 111 | <filename>/etc/locale.conf</filename> file:</para>
|
---|
[73e1db21] | 112 |
|
---|
[2164942] | 113 | <screen><userinput>cat > /etc/locale.conf << "EOF"
|
---|
| 114 | <literal># Begin /etc/locale.conf
|
---|
[73e1db21] | 115 |
|
---|
[6365b5d] | 116 | LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>.<replaceable>[charmap]</replaceable><replaceable>[@modifiers]</replaceable>
|
---|
[73e1db21] | 117 |
|
---|
[2164942] | 118 | # End /etc/locale.conf</literal>
|
---|
[73e1db21] | 119 | EOF</userinput></screen>
|
---|
| 120 |
|
---|
[6365b5d] | 121 | <para>Note that you can modify <filename>/etc/locale.conf</filename> with
|
---|
| 122 | Systemd <command>localectl</command> utility. To use
|
---|
| 123 | <command>localectl</command> for the example above, run:</para>
|
---|
| 124 |
|
---|
| 125 | <screen role="nodump"><userinput>localectl set-locale LANG="<replaceable>[ll]_[CC][charmap][@modifiers]</replaceable>"</userinput></screen>
|
---|
| 126 |
|
---|
| 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
|
---|
[68a8a9f] | 130 | separate them with a space. An example where <envar>LANG</envar> is set as
|
---|
[6365b5d] | 131 | en_US.UTF-8 but <envar>LC_CTYPE</envar> is set as just en_US is:</para>
|
---|
| 132 |
|
---|
| 133 | <screen role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
|
---|
| 134 |
|
---|
| 135 | <note><para>Please note that <command>localectl</command> command can
|
---|
| 136 | be used only on a system booted with Systemd.</para></note>
|
---|
[73e1db21] | 137 | <para>Setting the keyboard layout, screen font, and locale-related
|
---|
| 138 | environment variables are the only internationalization steps needed to
|
---|
| 139 | support locales that use ordinary single-byte encodings and left-to-right
|
---|
[9c06d27e] | 140 | writing direction. UTF-8 has been tested on the English, French, German,
|
---|
[73e1db21] | 141 | Italian, and Spanish locales. All other locales are untested. If you discover
|
---|
[9c06d27e] | 142 | issues with any other locale please open a ticket in our Trac system.</para>
|
---|
[73e1db21] | 143 |
|
---|
[9c06d27e] | 144 | <para>Some locales need additional programs and support. CLFS will not be
|
---|
| 145 | supporting these locales in the book. We welcome the support for these other
|
---|
| 146 | locales via <ulink url="&cblfs-root;"/>.</para>
|
---|
[73e1db21] | 147 |
|
---|
| 148 | </sect1>
|
---|