[arch-projects] [initscripts][PATCH v2] locale.sh: add support for user-specific locale.conf
Tom Gundersen
teg at jklm.no
Sat Aug 25 05:34:51 EDT 2012
We use the first configuration file we find out of:
* $XDG_CONFIG_HOME/locale.conf
* /etc/locale.conf
* /etc/rc.conf
All subsequent config files are ignored. E.g., an emtpy /etc/locale.conf
means that LOCALE from rc.conf is ignored.
Note that currently $XDG_CONFIG_HOME is unlikely to be set when
locale.sh is sourced, so it will not have any effect. In the future this
might change, so we kept it in.
This will easily allow users to set one locale to be used for
daemons/boot and a separate one to be used for users consoles etc.
This eliminates the need for DAEMON_LOCALE, so remove that
functionality. A post-install note will be added.
The constraints that led to this suggestion:
1) The default locale should work even if locale-gen has not been run,
i.e., it should be "C".
2) It is common to want the system locale to be "English", which a
priori "C" satisfies. However, "C" is not UTF-8, which causes issues
when the user locale is in UTF-8 (as it is the system locale that
configures the console mode).
3) Users might (and often do) want a different locale than what is used
system-wide. Moreover, different users might want different locales.
In case this seems far-fetched: This computer is shared by two people
neither of whose mother tongue is English (and whose mother tongue
is not the same). I also want all my daemons to output in English so I can
paste the output in bug reports etc.
v2: make sure $XDG_CONFIG_HOME and $HOME are set before using them
Signed-off-by: Tom Gundersen <teg at jklm.no>
---
functions | 24 ++++++++----------------
locale.sh | 10 ++++++----
rc.conf.5.txt | 13 +++----------
3 files changed, 17 insertions(+), 30 deletions(-)
diff --git a/functions b/functions
index e8ff7b8..7e7549a 100644
--- a/functions
+++ b/functions
@@ -9,7 +9,14 @@ localevars=(LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY
LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE
LC_MEASUREMENT LC_IDENTIFICATION LC_ALL)
-vconsolevars=(KEYMAP KEYMAP_TOGGLE FONT FONT_MAP FONT_UNIMAP)
+
+# clear the TZ envvar, so daemons always respect /etc/localtime
+unset TZ
+
+# sanitize the locale settings
+unset "${localevars[@]}"
+
+. /etc/profile.d/locale.sh
if [[ $1 == "start" ]]; then
if [[ $STARTING ]]; then
@@ -66,12 +73,6 @@ if (( $? != 3 )); then
fi
unset TERM_COLORS
-# clear the TZ envvar, so daemons always respect /etc/localtime
-unset TZ
-
-# sanitize the locale settings
-unset "${localevars[@]}"
-
parse_envfile() {
local file=$1 validkeys=("${@:2}") ret=0 lineno=0 key= val=
local -r quotes=$'[\'"]' comments=$'[;#]*'
@@ -723,15 +724,6 @@ if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then
declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1
fi
-if [[ $DAEMON_LOCALE != [nN][oO] ]]; then
- export LANG=${LOCALE:-C}
- if [[ -r /etc/locale.conf ]]; then
- parse_envfile /etc/locale.conf "${localevars[@]}"
- fi
-else
- export LANG=C
-fi
-
# set colors
if [[ $USECOLOR != [nN][oO] ]]; then
if tput setaf 0 &>/dev/null; then
diff --git a/locale.sh b/locale.sh
index c465f6f..e310318 100644
--- a/locale.sh
+++ b/locale.sh
@@ -1,10 +1,12 @@
unset LANG
-if [ -s /etc/locale.conf ]; then
+if [ -n $XDG_CONFIG_HOME ] && [ -s $XDG_CONFIG_HOME/locale.conf ]; then
+ . $XDG_CONFIG_HOME/locale.conf
+elif [ -n $HOME ] && [ -s $HOME/.config/locale.conf ]; then
+ . $HOME/.config/locale.conf
+elif [ -s /etc/locale.conf ]; then
. /etc/locale.conf
-fi
-
-if [ -z "$LANG" ] && [ -s /etc/rc.conf ]; then
+elif [ -s /etc/rc.conf ]; then
LANG=$(. /etc/rc.conf 2>/dev/null; echo "$LOCALE")
fi
diff --git a/rc.conf.5.txt b/rc.conf.5.txt
index 73c2423..8983871 100644
--- a/rc.conf.5.txt
+++ b/rc.conf.5.txt
@@ -190,21 +190,14 @@ FONT_MAP in /etc/vconsole.conf takes precedence (see vconsole.conf(5)), and is r
This sets your system language, which will be used by all i18n-friendly applications and utilities.
See `locale -a` (or locale.gen) for available options.
-LANG in /etc/locale.conf takes precedence (see locale.conf(5)), and is recommended.
+LANG in /etc/locale.conf takes precedence (see locale.conf(5)), and is recommended. User-specific
+locale settings which override both /etc/locale.conf and /etc/rc.conf are set in
+$XDG_CONFIG_HOME/locale.conf using the same syntax as /etc/locale.conf.
If unset, it falls back to the C locale.
LOCALE="en_US.UTF-8"
-*DAEMON_LOCALE=*
-
- - If set to 'no', export the C locale to daemons and during the boot process.
- - Otherwise, export LANG (or LOCALE) as configured in /etc/locale.conf (or /etc/rc.conf).
-
-Leave this unset, unless you have a specific reason to set it to 'no'.
-
- DAEMON_LOCALE="yes"
-
*USECOLOR=*
Use ANSI color sequences in start-up messages, unless set to 'no'.
--
1.7.12
More information about the arch-projects
mailing list