slitaz-tools view tinyutils/tazlocale @ rev 943

Move translations to use '%s'. Fix subox icon and allow it to work with spaces in the path.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jun 04 17:11:36 2015 +0300 (2015-06-04)
parents 5d80f6fdbdb7
children 3e742c2981ea
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-2015 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.'
19 newline; boldify "$(_ 'Usage:')"
20 echo " tazlocale [$(_ 'option')]"
22 newline; boldify "$(_ 'Options:')"
23 optlist "\
24 info $(_ 'Show info about config file and current locale.')
25 list $(_ 'Show list of available locales.')"
27 newline
28 _ 'Any other option treated as locale - set locale (root).'
29 _ 'Display locale selecting dialog if no option given (root).'
30 newline
31 }
34 # Make symlink to file, substitute "%%" to "ll_CC", "ll" or "en" according to
35 # current language settings and file existence
36 # (where "ll_CC" - full locale format (lang and country, and maybe, modifier).
38 make_i18n_link() {
39 if [ -d $(dirname ${1/.%%/}) ]; then
40 cd $(dirname ${1/.%%/})
42 if [ -e ${1/%%/$LANG} ]; then
43 ln -fs $(basename ${1/%%/$LANG}) ${1/.%%/}
44 else
45 if [ -e ${1/%%/$LANGUAGE} ]; then
46 ln -fs $(basename ${1/%%/$LANGUAGE}) ${1/.%%/}
47 else
48 ln -fs $(basename ${1/%%/en}) ${1/.%%/}
49 fi
50 fi
51 fi
52 }
55 # Create symlink to translated files provided by SliTaz language pack,
56 # doc and config files.
58 link_language_files() {
59 . /etc/locale.conf
60 LANGUAGE=${LANG%_*}
61 [ "$LANG" == 'POSIX' ] && LANGUAGE='en'
63 # Openbox menu
64 make_i18n_link /etc/xdg/openbox/menu.%%.xml
66 # Documentation
67 make_i18n_link /usr/share/doc/slitaz/index.%%.html
69 # SliTaz Software Manuals
70 for soft in tazpkg tazlito tazusb tazwok tazweb cookutils; do
71 make_i18n_link /usr/share/doc/$soft/$soft.%%.html
72 done
74 # SliTaz TazWeb "My Web Home"
75 make_i18n_link /usr/share/tazweb/home.%%.html
77 # SliTaz WebHome
78 make_i18n_link /usr/share/webhome/index.%%.html
80 # TazPanel Doc under www
81 make_i18n_link /var/www/tazpanel/doc/tazpanel.%%.html
83 # SliTaz Tools Manuals
84 for soft in burnbox tazinst; do
85 make_i18n_link /usr/share/doc/slitaz-tools/$soft.%%.html
86 done
87 }
90 # Locale name displayed.
92 get_locale_name() {
93 for i in $(ls -1 /usr/share/i18n/locales | grep [a-z]_[A-Z]); do
94 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
95 echo "$i Locale"
96 done
97 }
100 # We have no locale files in /usr/lib/locale by default.
101 # Run localedef in background to have a faster boot.
103 gen_utf8_locale() {
104 [ -e /usr/lib/locale/$locale ] || \
105 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
106 }
109 # Config /etc/locale.conf
111 system_config() {
112 export LC_ALL=$locale
113 _n 'Setting system locale to: %s' "$locale"
114 echo -e "LANG=$locale\nLC_ALL=$locale" > /etc/locale.conf
115 status
116 gen_utf8_locale
117 link_language_files
118 }
121 # Dialog menu.
123 dialog_menu() {
124 exec 3>&1
125 locale=$($DIALOG --clear \
126 --title "{ $(_n 'SliTaz language setting') }" \
127 --menu "" 20 72 14 \
128 "en" "English" \
129 $(get_locale_name) \
130 2>&1 1>&3)
131 retval=$?
132 exec 3>&-
133 case $retval in
134 0) continue ;;
135 1|255) exit 0 ;;
136 esac
138 # Default: POSIX => English
139 [ "$locale" = 'en' ] && locale='en_US'
140 [ -s /etc/locale.conf ] && RECONFIG='yes'
142 # If it's a reconfiguration give an info message.
143 if [ -n "$RECONFIG" ]; then
144 export LC_ALL=$locale
145 msg=$(_n "\
146 Please logout of your current session and login again to use new locale.")
147 $DIALOG --clear --title " $(_n 'Information') " --msgbox "$msg" 16 70
148 fi
149 system_config
150 }
152 case "$1" in
153 --help|-h)
154 usage ;;
155 info)
156 _ 'Config file: %s' '/etc/locale.conf'
157 _ 'Current locale: %s' "$LANG"
158 ;;
159 list)
160 list=
161 for i in $(ls -1 /usr/share/i18n/locales | grep '[a-z]_[A-Z]'); do
162 desc=$(fgrep -m1 title /usr/share/i18n/locales/$i | cut -d'"' -f2)
163 list="$list
164 $i $desc"
165 done
166 optlist "$list" ;;
167 "")
168 # No args: display Ncurses dialog.
169 : ${DIALOG=dialog --timeout 60}
170 check_root $@
171 dialog_menu ;;
172 *)
173 # Usage: tazlocale LANG_COUNTRY
174 locale=$1
175 check_root $@
176 system_config ;;
177 esac
179 exit 0