slitaz-tools view tinyutils/tazlocale @ rev 1033

Update tazinst.html link
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 20 07:04:25 2020 +0000 (2020-08-20)
parents 491239328786
children e26016781ea8
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 if [ -d $(dirname ${1/.%%/}) ]; then
39 cd $(dirname ${1/.%%/})
41 if [ -e ${1/%%/$LANG} ]; then
42 ln -fs $(basename ${1/%%/$LANG}) ${1/.%%/}
43 else
44 if [ -e ${1/%%/$LANGUAGE} ]; then
45 ln -fs $(basename ${1/%%/$LANGUAGE}) ${1/.%%/}
46 else
47 ln -fs $(basename ${1/%%/en}) ${1/.%%/}
48 fi
49 fi
50 fi
51 }
54 # Create symlink to translated files provided by SliTaz language pack,
55 # doc and config files.
57 link_language_files() {
58 . /etc/locale.conf
59 LANGUAGE=${LANG%_*}
60 [ "$LANG" = 'POSIX' ] && LANGUAGE='en'
62 # Openbox menu
63 make_i18n_link /etc/xdg/openbox/menu.%%.xml
65 # Documentation
66 make_i18n_link /usr/share/doc/slitaz/index.%%.html
68 # SliTaz Software Manuals
69 for soft in tazpkg tazlito tazusb tazwok tazweb tazinst cookutils; do
70 make_i18n_link /usr/share/doc/$soft/$soft.%%.html
71 done
73 # SliTaz TazWeb "My Web Home"
74 make_i18n_link /usr/share/tazweb/home.%%.html
76 # SliTaz WebHome
77 make_i18n_link /usr/share/webhome/index.%%.html
79 # TazPanel Doc under www
80 make_i18n_link /var/www/tazpanel/doc/tazpanel.%%.html
82 # SliTaz Tools Manuals
83 for soft in burnbox tazinst; do
84 make_i18n_link /usr/share/doc/slitaz-tools/$soft.%%.html
85 done
86 }
89 # Locale name displayed.
91 locale_names() {
92 [ -d /usr/share/i18n/locales ] &&
93 ls -1 /usr/share/i18n/locales | grep [a-z]_[A-Z]
94 }
96 get_locale_name() {
97 for i in $(locale_names); do
98 echo -n "$i "
99 desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
100 if [ -n "$desc" ]; then
101 echo "$desc" | tr -c '[A-Za-z0-9\n]' '_'
102 else
103 echo "Locale"
104 fi
105 done
106 }
109 # We have no locale files in /usr/lib/locale by default.
110 # Run localedef in background to have a faster boot.
112 gen_utf8_locale() {
113 if [ ! -d "/usr/lib/locale/$locale.UTF-8" ]; then
114 mkdir -p /usr/lib/locale
115 localedef -i "$locale" -c -f 'UTF-8' "/usr/lib/locale/$locale.UTF-8" &
116 fi
117 }
120 # Config /etc/locale.conf
122 system_config() {
123 # If locale not defined: show error and exit
124 ls "/usr/share/i18n/locales/$locale" >/dev/null || return
125 export LC_ALL="$locale.UTF-8"
126 action 'Setting system locale to: %s' "$locale.UTF-8"
127 echo -e "LANG=$locale.UTF-8\nLC_ALL=$locale.UTF-8" > /etc/locale.conf
128 status
129 gen_utf8_locale
130 link_language_files
131 # Clean TazPanel cached headers in old language
132 [ -n "$(which tazpanel)" ] && tazpanel cc
133 }
136 # Dialog menu.
138 dialog_menu() {
139 exec 3>&1
140 locale=$($DIALOG --clear \
141 --title "{ $(_n 'SliTaz language setting') }" \
142 --menu "" 20 72 14 \
143 "en" "English" \
144 $(get_locale_name) \
145 2>&1 1>&3)
146 retval=$?
147 exec 3>&-
148 case $retval in
149 0) continue ;;
150 1|255) exit 0 ;;
151 esac
153 # Default: POSIX => English
154 [ "$locale" = 'en' ] && locale='en_US'
155 [ -s /etc/locale.conf ] && RECONFIG='yes'
157 # If it's a reconfiguration give an info message.
158 if [ -n "$RECONFIG" ]; then
159 export LC_ALL=$locale
160 msg=$(_n "\
161 Please logout of your current session and login again to use new locale.")
162 $DIALOG --clear --title " $(_n 'Information') " --msgbox "$msg" 16 70
163 fi
164 system_config
165 }
167 case "$1" in
168 --help|-h)
169 usage ;;
170 info)
171 . /etc/locale.conf
172 _ 'Config file: %s' '/etc/locale.conf'
173 _ 'Current locale: %s' "$LANG"
174 ;;
175 list)
176 list=
177 for i in $(locale_names); do
178 desc=$(fgrep -m1 title /usr/share/i18n/locales/$i | cut -d'"' -f2)
179 list="$list
180 $i $desc"
181 done
182 optlist "$list" ;;
183 "")
184 # No args: display Ncurses dialog.
185 : ${DIALOG=dialog --timeout 60}
186 check_root $@
187 dialog_menu ;;
188 *)
189 # Usage: tazlocale LANG_COUNTRY
190 locale=$1
191 check_root $@
192 system_config ;;
193 esac
195 exit 0