slitaz-tools view tinyutils/tazlocale @ rev 764

tazinst: remove (cooking) from grub menu template
author Richard Dunbar <mojo@slitaz.org>
date Tue May 15 06:41:31 2012 +0000 (2012-05-15)
parents f73c8f4bb66c
children 8c8b2c646040
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-2012 SliTaz GNU/Linux - BSD License
7 #
8 # Author: Christophe Lincoln <pankso@slitaz.org>
9 #
10 . /lib/libtaz.sh
12 # Internationalization
13 . /usr/bin/gettext.sh
14 TEXTDOMAIN='slitaz-tools'
15 export TEXTDOMAIN
17 # Create symlink to translated files provided by SliTaz language pack,
18 # doc and config files.
19 link_language_files()
20 {
21 . /etc/locale.conf
22 LANGUAGE=${LANG%_*}
23 [ "$LANG" = "POSIX" ] && LANGUAGE="en"
24 # Openbox menu in /usr/share/doc/slitaz
25 if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then
26 cd /etc/xdg/openbox && rm -f menu.xml
27 ln -s menu.$LANGUAGE.xml menu.xml
28 fi
29 # Documentation in /usr/share/doc/slitaz
30 if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then
31 cd /usr/share/doc/slitaz && rm -f index.html
32 ln -s index.$LANGUAGE.html index.html
33 fi
34 # SliTaz Software Manuals
35 for soft in tazpkg tazlito tazusb tazwok tazweb tazpanel
36 do
37 if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then
38 cd /usr/share/doc/$soft && rm -f $soft.html
39 ln -s $soft.$LANGUAGE.html $soft.html
40 fi
41 done
42 # SliTaz TazWeb "My Web Home"
43 if [ -f /usr/share/tazweb/home.$LANGUAGE.html ]; then
44 cd /usr/share/tazweb && rm -f home.html
45 ln -s home.$LANGUAGE.html home.html
46 fi
47 # SliTaz WebHome
48 if [ -f /usr/share/webhome/index.$LANGUAGE.html ]; then
49 cd /usr/share/webhome && rm -f index.html
50 ln -s index.$LANGUAGE.html index.html
51 fi
52 # SliTaz Tools Manuals
53 for soft in tazinst
54 do
55 if [ -f /usr/share/doc/slitaz/$soft.$LANGUAGE.html ]; then
56 cd /usr/share/doc/slitaz && rm -f $soft.html
57 ln -s $soft.$LANGUAGE.html $soft.html
58 fi
59 done
60 }
62 # Locale name displayed.
63 get_locale_name()
64 {
65 for i in $(ls -1 /usr/share/i18n/locales | grep ^[a-z][a-z]_[A-Z][A-Z])
66 do
67 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
68 echo "$i Locale"
69 done
70 }
72 # We have no locale files in /usr/lib/locale by default. Run localedef in
73 # background to have a faster boot.
74 gen_utf8_locale()
75 {
76 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
77 }
79 # Config /etc/locale.conf
80 system_config() {
81 export LC_ALL=$locale
82 gettext "Setting system locale to:"; echo -n " $locale"
83 echo "LANG=$locale" > /etc/locale.conf
84 echo "LC_ALL=$locale" >> /etc/locale.conf
85 # Resource libtaz.sh to get status message in the correct locale.
86 . /lib/libtaz.sh && status
87 gen_utf8_locale
88 link_language_files
89 }
91 # Dialog menu.
92 dialog_menu()
93 {
94 exec 3>&1
95 locale=$($DIALOG --clear \
96 --title " $(gettext "SliTaz language configuration") " \
97 --menu "" 15 70 5 \
98 "en" "English" \
99 $(get_locale_name) \
100 2>&1 1>&3)
101 retval=$?
102 exec 3>&-
103 case $retval in
104 0) continue ;;
105 1|255) exit 0 ;;
106 esac
108 # Default: POSIX = English
109 [ "$locale" = "en" ] && locale="en_US"
110 [ -s /etc/locale.conf ] && RECONFIG="yes"
112 # If it's a reconfiguration give an info message.
113 if [ -n "$RECONFIG" ]; then
114 export LC_ALL=$locale
115 msg=$(gettext "\
116 Please logout of your current session and login again to use new locale.")
117 $DIALOG --clear --title " Information " --msgbox "$msg" 16 70
118 fi
119 system_config
120 }
122 case "$1" in
123 info)
124 gettext "Config file :"; echo " /etc/locale.conf"
125 gettext "Current locale:"; echo " $LANG" ;;
126 list)
127 for i in $(ls -1 /usr/share/i18n/locales | grep ^[a-z][a-z]_[A-Z][A-Z])
128 do
129 desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
130 echo "$i $desc"
131 done ;;
132 "")
133 # No args: display Ncurses dialog.
134 : ${DIALOG=dialog}
135 check_root
136 dialog_menu ;;
137 *)
138 # Usage: tazlocale LANG_COUNTRY
139 locale=$1
140 check_root
141 system_config
142 gen_utf8_locale
143 link_language_files ;;
144 esac
146 exit 0