Changeset 6ebb3b9


Ignore:
Timestamp:
01/28/2024 12:43:40 PM (3 months ago)
Author:
Xi Ruoyao <xry111@…>
Branches:
12.1, 12.1-rc1, multilib, trunk, xry111/arm64, xry111/clfs-ng, xry111/loongarch, xry111/loongarch-12.1, xry111/mips64el, xry111/update-glibc
Children:
ee950a5e
Parents:
8497448
git-author:
Xi Ruoyao <xry111@…> (01/28/2024 12:41:00 PM)
git-committer:
Xi Ruoyao <xry111@…> (01/28/2024 12:43:40 PM)
Message:

Unify locale settings in sysv and systemd

Do not duplicate large paragraphs of texts.

Always use C locale if running in a Linux console. Create /etc/profile
for systemd too, but reading the locale setting from /etc/locale.conf.

Location:
chapter09
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • chapter09/chapter09.xml

    r8497448 r6ebb3b9  
    2727  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="network.xml"/>
    2828  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="usage.xml"/>
    29   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="profile.xml"/>
    3029
    3130  <!-- systemd -->
    3231  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="clock.xml"/>
    3332  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="consoled.xml"/>
    34   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="locale.xml"/>
    3533
    3634  <!-- common -->
     35  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="locale.xml"/>
    3736  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="inputrc.xml"/>
    3837  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="etcshells.xml"/>
  • chapter09/locale.xml

    r8497448 r6ebb3b9  
    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 revision='systemd'>The <filename>/etc/locale.conf</filename> file
     22  below sets some environment variables necessary for native language
     23  support. Setting them properly results in:</para>
     24
     25  <para>Some environment variables are necessary for native language
     26  support. Setting them properly results in:</para>
    2027
    2128  <itemizedlist>
     
    98105  might provide some useful information.</para>
    99106
    100   <para>Once the proper locale settings have been determined, create the
    101   <filename>/etc/locale.conf</filename> file:</para>
    102 
    103 <screen><userinput>cat &gt; /etc/locale.conf &lt;&lt; "EOF"
     107  <para revision='systemd'>Once the proper locale settings have been
     108  determined, create the <filename>/etc/locale.conf</filename> file:</para>
     109
     110<screen revision='systemd'><userinput>cat &gt; /etc/locale.conf &lt;&lt; "EOF"
    104111<literal>LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable></literal>
    105112EOF</userinput></screen>
    106113
    107   <para>Note that you can modify <filename>/etc/locale.conf</filename> with the
     114  <para>The shell program <command>/bin/bash</command> (here after referred
     115  as <quote>the shell</quote>) uses a collection of startup files to help
     116  create the environment to run in. Each file has a specific use and may
     117  affect login and interactive environments differently. The files in the
     118  <filename class="directory">/etc</filename> directory provide global
     119  settings.  If equivalent files exist in the home directory, they
     120  may override the global settings.</para>
     121
     122  <para>An interactive login shell is started after a successful login,
     123  using <command>/bin/login</command>, by reading the
     124  <filename>/etc/passwd</filename> file.  An interactive non-login shell is
     125  started at the command-line (e.g.
     126  <prompt>[prompt]$</prompt><command>/bin/bash</command>).  A
     127  non-interactive shell is usually present when a shell script is running.
     128  It is non-interactive because it is processing a script and not waiting
     129  for user input between commands.</para>
     130
     131  <para><phrase revision='systemd'>The login shells are often unaffected by
     132  the settings in <filename>/etc/locale.conf</filename>. </phrase>Create the
     133  <filename>/etc/profile</filename>
     134  <phrase revision='sysv'>once the proper locale settings have been
     135  determined to set the desired locale</phrase><phrase
     136  revision='systemd'>to read the locale settings from
     137  <filename>/etc/locale.conf</filename> and export them</phrase>,
     138  but set the <literal>C</literal> locale instead if running in the Linux
     139  console (to prevent programs from outputting characters that the Linux
     140  console is unable to render):</para>
     141
     142<screen revision="systemd"><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
     143<literal># Begin /etc/profile
     144
     145for i in $(locale); do
     146  unset ${i%=*}
     147done
     148
     149if [[ "$TERM" = linux ]]; then
     150  export LANG=C
     151else
     152  source /etc/locale.conf
     153
     154  for i in $(locale); do
     155    key=${i%=*}
     156    if [[ -v $key ]]; then
     157      export $key
     158    fi
     159  done
     160fi
     161
     162# End /etc/profile</literal>
     163EOF</userinput></screen>
     164
     165<screen revision="sysv"><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
     166<literal># Begin /etc/profile
     167
     168for i in $(locale); do
     169  unset ${i%=*}
     170done
     171
     172if [[ "$TERM" = linux ]]; then
     173  for i in $(locale); do
     174    unset ${i%=*}
     175  done
     176
     177  export LANG=C
     178else
     179  export LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>
     180fi
     181
     182# End /etc/profile</literal>
     183EOF</userinput></screen>
     184
     185  <para revision='systemd'>Note that you can modify <filename>/etc/locale.conf</filename> with the
    108186  systemd <command>localectl</command> utility. To use
    109187  <command>localectl</command> for the example above, run:</para>
    110188
    111 <screen role="nodump"><userinput>localectl set-locale LANG="<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>"</userinput></screen>
    112 
    113   <para>You can also specify other language specific environment variables such
    114   as <envar>LANG</envar>, <envar>LC_CTYPE</envar>, <envar>LC_NUMERIC</envar> or
    115   any other environment variable from <command>locale</command> output. Just
    116   separate them with a space. An example where <envar>LANG</envar> is set as
     189<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>
     190
     191  <para revision='systemd'>You can also specify other language specific
     192  environment variables such as <envar>LANG</envar>,
     193  <envar>LC_CTYPE</envar>, <envar>LC_NUMERIC</envar> or any other
     194  environment variable from <command>locale</command> output. Just separate
     195  them with a space. An example where <envar>LANG</envar> is set as
    117196  en_US.UTF-8 but <envar>LC_CTYPE</envar> is set as just en_US is:</para>
    118197
    119 <screen role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
    120 
    121   <note><para>Please note that the <command>localectl</command> command
    122   doesn't work in the chroot environment.  It can only
    123   be used after the LFS system is booted with systemd.</para></note>
     198<screen revision='systemd' role="nodump"><userinput>localectl set-locale LANG="en_US.UTF-8" LC_CTYPE="en_US"</userinput></screen>
     199
     200  <note revision='systemd'><para>Please note that the
     201  <command>localectl</command> command doesn't work in the chroot
     202  environment.  It can only be used after the LFS system is booted with
     203  systemd.</para></note>
    124204
    125205  <para>The <literal>C</literal> (default) and <literal>en_US</literal>
     
    135215  if you are certain that you will never need 8-bit characters.</para>
    136216
    137 <!--
    138   <para>UTF-8 based locales are not supported well by many programs.
    139   Work is in progress to document and, if possible, fix such problems, see
    140   <ulink url="&blfs-book;introduction/locale-issues.html"/>.</para>
    141 -->
    142 
    143217</sect1>
Note: See TracChangeset for help on using the changeset viewer.