Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • chapter09/locale.xml

    r4f560248 r4ecfc55  
    1 <?xml version="1.0" encoding="ISO-8859-1"?>
     1<?xml version="1.0" encoding="UTF-8"?>
    22<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
    33  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
     
    66]>
    77
    8 <sect1 id="ch-config-locale" revision="systemd">
     8<sect1 id="ch-config-locale">
    99  <?dbhtml filename="locale.html"?>
    1010
     
    1212
    1313  <indexterm zone="ch-config-locale">
    14     <primary sortas="e-etc-locale-conf">/etc/locale.conf</primary>
     14    <primary sortas="e-/etc/profile">/etc/profile</primary>
    1515  </indexterm>
    1616
    17   <para>The <filename>/etc/locale.conf</filename> file below sets some
    18   environment variables necessary for native language support. Setting
    19   them properly results in:</para>
     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>
    2023
    2124  <itemizedlist>
     
    4043
    4144  <para>Replace <replaceable>&lt;ll&gt;</replaceable> below with the two-letter code
    42   for your desired language (e.g., <quote>en</quote>) and
     45  for your desired language (e.g., <literal>en</literal>) and
    4346  <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
     47  country (e.g., <literal>GB</literal>). <replaceable>&lt;charmap&gt;</replaceable> should
    4548  be replaced with the canonical charmap for your chosen locale. Optional
    46   modifiers such as <quote>@euro</quote> may also be present.</para>
     49  modifiers such as <literal>@euro</literal> may also be present.</para>
    4750
    4851  <para>The list of all locales supported by Glibc can be obtained by running
     
    5154<screen role="nodump"><userinput>locale -a</userinput></screen>
    5255
    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>.
     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>.
    5559  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 the safest in most
     60  that <literal>UTF-8</literal> is written as <literal>UTF-8</literal>, not
     61  <literal>utf8</literal>), so it is the safest in most
    5862  cases to choose the canonical name for a particular locale. To determine
    5963  the canonical name, run the following command, where <replaceable>&lt;locale
    6064  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>
     65  your preferred locale (<literal>en_GB.iso88591</literal> in our
     66  example).</para>
    6267
    6368<screen role="nodump"><userinput>LC_ALL=<replaceable>&lt;locale name&gt;</replaceable> locale charmap</userinput></screen>
    6469
    65   <para>For the <quote>en_GB.iso88591</quote> locale, the above command
     70  <para>For the <literal>en_GB.iso88591</literal> locale, the above command
    6671  will print:</para>
    6772
    6873<screen><computeroutput>ISO-8859-1</computeroutput></screen>
    6974
    70   <para>This results in a final locale setting of <quote>en_GB.ISO-8859-1</quote>.
     75  <para>This results in a final locale setting of <literal>en_GB.ISO-8859-1</literal>.
    7176  It is important that the locale found using the heuristic above is tested prior
    7277  to it being added to the Bash startup files:</para>
     
    9196  Glibc.</para>
    9297
    93   <!-- FIXME: the xlib example will become obsolete in the future.-->
    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>
    98 
    99 <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
    100 
    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>
    108 
    10998  <para>Other packages can also function incorrectly (but may not necessarily
    11099  display any error messages) if the locale name does not meet their expectations.
     
    112101  might provide some useful information.</para>
    113102
    114   <para>Once the proper locale settings have been determined, create the
    115   <filename>/etc/locale.conf</filename> file:</para>
    116 
    117 <screen><userinput>cat &gt; /etc/locale.conf &lt;&lt; "EOF"
     103  <para revision='systemd'>Once the proper locale settings have been
     104  determined, create the <filename>/etc/locale.conf</filename> file:</para>
     105
     106<screen revision='systemd'><userinput>cat &gt; /etc/locale.conf &lt;&lt; "EOF"
    118107<literal>LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable></literal>
    119108EOF</userinput></screen>
    120109
    121   <para>Note that you can modify <filename>/etc/locale.conf</filename> with the
     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>,
     134  but set the <literal>C.UTF-8</literal> locale instead if running in the Linux
     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 &gt; /etc/profile &lt;&lt; "EOF"
     139<literal># Begin /etc/profile
     140
     141for i in $(locale); do
     142  unset ${i%=*}
     143done
     144
     145if [[ "$TERM" = linux ]]; then
     146  export LANG=C.UTF-8
     147else
     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
     156fi
     157
     158# End /etc/profile</literal>
     159EOF</userinput></screen>
     160
     161<screen revision="sysv"><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
     162<literal># Begin /etc/profile
     163
     164for i in $(locale); do
     165  unset ${i%=*}
     166done
     167
     168if [[ "$TERM" = linux ]]; then
     169  export LANG=C.UTF-8
     170else
     171  export LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>
     172fi
     173
     174# End /etc/profile</literal>
     175EOF</userinput></screen>
     176
     177  <para revision='systemd'>Note that you can modify <filename>/etc/locale.conf</filename> with the
    122178  systemd <command>localectl</command> utility. To use
    123179  <command>localectl</command> for the example above, run:</para>
    124180
    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>
    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
    130   separate them with a space. An example where <envar>LANG</envar> is set as
     181<screen revision='systemd' role="nodump"><userinput>localectl set-locale LANG="<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>"</userinput></screen>
     182
     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
    131188  en_US.UTF-8 but <envar>LC_CTYPE</envar> is set as just en_US is:</para>
    132189
    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 the <command>localectl</command> command
    136   doesn't work in the chroot environment.  It can only
    137   be used after the LFS system is booted with systemd.</para></note>
    138 
    139   <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
    140   one for United States English users) locales are different. <quote>C</quote>
     190<screen revision='systemd' role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
     191
     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>
     196
     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>
    141200  uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
    142201  as invalid characters. That's why, e.g., the <command>ls</command> command
    143202  substitutes them with question marks in that locale. Also, an attempt to send
    144203  mail with such characters from Mutt or Pine results in non-RFC-conforming
    145   messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
    146   8-bit</quote>). It's suggested that you use the <quote>C</quote> locale only
     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
    147207  if you are certain that you will never need 8-bit characters.</para>
    148208
    149 <!--
    150   <para>UTF-8 based locales are not supported well by many programs.
    151   Work is in progress to document and, if possible, fix such problems, see
    152   <ulink url="&blfs-book;introduction/locale-issues.html"/>.</para>
    153 -->
    154 
    155209</sect1>
Note: See TracChangeset for help on using the changeset viewer.