slitaz-tools view tinyutils/tazlocale @ rev 1035
Update tazinst.html link (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Aug 21 09:59:00 2020 +0000 (2020-08-21) |
parents | e26016781ea8 |
children |
line source
1 #!/bin/sh
2 #
3 # Tazlocale: SliTaz GNU/Linux locale setting using dialog boxes.
4 # Configuration file is: /etc/locale.conf
5 #
6 # Copyright (C) 2008-2017 SliTaz GNU/Linux - BSD License
7 #
8 # Author: Christophe Lincoln <pankso@slitaz.org>
9 #
11 . /lib/libtaz.sh
12 export TEXTDOMAIN='slitaz-tools' #i18n
15 usage() {
16 newline
17 _ 'SliTaz GNU/Linux locale setting using dialog boxes.'
18 newline
19 boldify "$(_ 'Usage:')"
20 echo " tazlocale [$(_ 'option')]"
21 newline
22 boldify "$(_ 'Options:')"
23 optlist "\
24 info $(_ 'Show info about config file and current locale.')
25 list $(_ 'Show list of available locales.')"
26 newline
27 _ 'Any other option treated as locale - set locale (root).'
28 _ 'Display locale selecting dialog if no option given (root).'
29 newline
30 }
33 # Make symlink to file, substitute "%%" to "ll_CC", "ll" or "en" according to
34 # current language settings and file existence
35 # (where "ll_CC" - full locale format (lang and country, and maybe, modifier).
37 make_i18n_link() {
38 for i in $LANG $LANGUAGE en; do
39 [ -e ${1/.%%./.$i.} ] || continue
40 [ "$(readlink ${1/.%%/})" = "$(basename ${1/.%%./.$i.})" ] ||
41 ln -fs $(basename ${1/.%%./.$i.}) ${1/.%%/}
42 break
43 done
44 }
47 # Create symlink to translated files provided by SliTaz language pack,
48 # doc and config files.
50 link_language_files() {
51 . /etc/locale.conf
52 LANGUAGE=${LANG%_*}
53 [ "$LANG" = 'POSIX' ] && LANGUAGE='en'
55 # Openbox menu
56 make_i18n_link /etc/xdg/openbox/menu.%%.xml
58 # Documentation & manuals
59 find /usr/share/doc -name '*.en.html' | \
60 while read doc; do
61 make_i18n_link ${doc/.en./.%%.}
62 done
64 # SliTaz TazWeb "My Web Home"
65 make_i18n_link /usr/share/tazweb/home.%%.html
67 # SliTaz WebHome
68 make_i18n_link /usr/share/webhome/index.%%.html
70 # TazPanel Doc under www
71 make_i18n_link /var/www/tazpanel/doc/tazpanel.%%.html
72 }
75 # Locale name displayed.
77 locale_names() {
78 [ -d /usr/share/i18n/locales ] &&
79 ls -1 /usr/share/i18n/locales | grep [a-z]_[A-Z]
80 }
82 get_locale_name() {
83 for i in $(locale_names); do
84 echo -n "$i "
85 desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
86 if [ -n "$desc" ]; then
87 echo "$desc" | tr -c '[A-Za-z0-9\n]' '_'
88 else
89 echo "Locale"
90 fi
91 done
92 }
95 # We have no locale files in /usr/lib/locale by default.
96 # Run localedef in background to have a faster boot.
98 gen_utf8_locale() {
99 if [ ! -d "/usr/lib/locale/$locale.UTF-8" ]; then
100 mkdir -p /usr/lib/locale
101 localedef -i "$locale" -c -f 'UTF-8' "/usr/lib/locale/$locale.UTF-8" &
102 fi
103 }
106 # Config /etc/locale.conf
108 system_config() {
109 # If locale not defined: show error and exit
110 ls "/usr/share/i18n/locales/$locale" >/dev/null || return
111 export LC_ALL="$locale.UTF-8"
112 action 'Setting system locale to: %s' "$locale.UTF-8"
113 echo -e "LANG=$locale.UTF-8\nLC_ALL=$locale.UTF-8" > /etc/locale.conf
114 status
115 gen_utf8_locale
116 link_language_files
117 # Clean TazPanel cached headers in old language
118 [ -n "$(which tazpanel)" ] && tazpanel cc
119 }
122 # Dialog menu.
124 dialog_menu() {
125 exec 3>&1
126 locale=$($DIALOG --clear \
127 --title "{ $(_n 'SliTaz language setting') }" \
128 --menu "" 20 72 14 \
129 "en" "English" \
130 $(get_locale_name) \
131 2>&1 1>&3)
132 retval=$?
133 exec 3>&-
134 case $retval in
135 0) continue ;;
136 1|255) exit 0 ;;
137 esac
139 # Default: POSIX => English
140 [ "$locale" = 'en' ] && locale='en_US'
141 [ -s /etc/locale.conf ] && RECONFIG='yes'
143 # If it's a reconfiguration give an info message.
144 if [ -n "$RECONFIG" ]; then
145 export LC_ALL=$locale
146 msg=$(_n "\
147 Please logout of your current session and login again to use new locale.")
148 $DIALOG --clear --title " $(_n 'Information') " --msgbox "$msg" 16 70
149 fi
150 system_config
151 }
153 case "$1" in
154 --help|-h)
155 usage ;;
156 info)
157 . /etc/locale.conf
158 _ 'Config file: %s' '/etc/locale.conf'
159 _ 'Current locale: %s' "$LANG"
160 ;;
161 list)
162 list=
163 for i in $(locale_names); do
164 desc=$(fgrep -m1 title /usr/share/i18n/locales/$i | cut -d'"' -f2)
165 list="$list
166 $i $desc"
167 done
168 optlist "$list" ;;
169 "")
170 # No args: display Ncurses dialog.
171 : ${DIALOG=dialog --timeout 60}
172 check_root $@
173 dialog_menu ;;
174 *)
175 # Usage: tazlocale LANG_COUNTRY
176 locale=$1
177 check_root $@
178 system_config ;;
179 esac
181 exit 0