slitaz-tools view tinyutils/tazlocale @ rev 728

tazlocale: added support for localizable webhome
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Apr 07 17:33:06 2012 +0300 (2012-04-07)
parents 29fe613b2eb6
children 433b4e383048
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 # 20110614 <pankso@slitaz.org> - GNU gpl.
7 #
9 # Internationalization
10 . /usr/bin/gettext.sh
11 TEXTDOMAIN='slitaz-tools'
12 export TEXTDOMAIN
14 # Check if user is root.
15 if test $(id -u) != 0; then
16 gettext "You must be root to run:"; echo " $(basename $0)"
17 gettext "Type su and root password to become super-user"; echo
18 exit 1
19 fi
21 # Create symlink to translated files provided by SliTaz language pack,
22 # doc and config files.
23 link_language_files()
24 {
25 . /etc/locale.conf
26 LANGUAGE=${LANG%_*}
27 [ "$LANG" = "C" ] && LANGUAGE="en"
28 # Openbox menu in /usr/share/doc/slitaz
29 if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then
30 cd /etc/xdg/openbox && rm -f menu.xml
31 ln -s menu.$LANGUAGE.xml menu.xml
32 fi
33 # Documentation in /usr/share/doc/slitaz
34 if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then
35 cd /usr/share/doc/slitaz && rm -f index.html
36 ln -s index.$LANGUAGE.html index.html
37 fi
38 # SliTaz Software Manuals
39 for soft in tazpkg tazlito tazusb tazwok tazweb tazpanel
40 do
41 if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then
42 cd /usr/share/doc/$soft && rm -f $soft.html
43 ln -s $soft.$LANGUAGE.html $soft.html
44 fi
45 done
46 # SliTaz TazWeb "My Web Home"
47 if [ -f /usr/share/tazweb/home.$LANGUAGE.html ]; then
48 cd /usr/share/tazweb && rm -f home.html
49 ln -s home.$LANGUAGE.html home.html
50 fi
51 # SliTaz WebHome
52 if [ -f /usr/share/webhome/index.$LANGUAGE.html ]; then
53 cd /usr/share/webhome && rm -f index.html
54 ln -s index.$LANGUAGE.html index.html
55 fi
56 # SliTaz Tools Manuals
57 for soft in burnbox tazinst
58 do
59 if [ -f /usr/share/doc/slitaz-tools/$soft.$LANGUAGE.html ]; then
60 cd /usr/share/doc/slitaz-tools && rm -f $soft.html
61 ln -s $soft.$LANGUAGE.html $soft.html
62 fi
63 done
64 }
66 # Locale name displayed.
67 get_locale_name()
68 {
69 for i in `ls -1 /usr/share/i18n/locales | grep ^[a-z][a-z]_[A-Z][A-Z]`
70 do
71 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
72 echo "$i Locale"
73 done
74 }
76 # We have no locale files in /usr/lib/locale by default. Run localedef in
77 # background to have a faster boot.
78 gen_utf8_locale()
79 {
80 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
81 }
83 # Dialog menu.
84 dialog_menu()
85 {
86 exec 3>&1
87 locale=`$DIALOG --clear \
88 --title " $(gettext "SliTaz language configuration") " \
89 --menu "" 15 70 5 \
90 "en" "English" \
91 $(get_locale_name) \
92 2>&1 1>&3`
93 retval=$?
94 exec 3>&-
95 case $retval in
96 0) continue ;;
97 1|255) exit 0 ;;
98 esac
100 # Default: C = English
101 [ "$locale" = "en" ] && locale="en_US"
102 [ -s /etc/locale.conf ] && RECONFIG="yes"
104 # System configuration
105 echo "LANG=$locale" > /etc/locale.conf
106 echo "LC_ALL=$locale" >> /etc/locale.conf
107 export LANG=$locale LC_ALL=$locale
108 gen_utf8_locale
109 get_messages
111 # If it's a reconfiguration give an info message.
112 if [ -n "$RECONFIG" ]; then
113 msg=$(gettext "\
114 Please logout of your current session and login again to use new locale.")
115 $DIALOG --clear \
116 --title " Information " \
117 --msgbox "$msg" 16 70
118 fi
119 }
121 case "$1" in
122 *_*)
123 # Execute functions (can be called from an other apps).
124 $1 ;;
125 list)
126 echo ""
127 locale -a
128 echo "" ;;
129 init)
130 # This command can be used to change system locale from cmdline.
131 locale=$2
132 echo "LANG=$locale" > /etc/locale.conf
133 echo "LC_ALL=$locale" >> /etc/locale.conf
134 gen_utf8_locale
135 link_language_files ;;
136 *)
137 : ${DIALOG=dialog}
138 dialog_menu
139 link_language_files ;;
140 esac
142 exit 0