slitaz-tools view tinyutils/tazlocale @ rev 595

Dev null when killing Xorg at boot
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 16 22:19:25 2011 +0200 (2011-05-16)
parents 6017afdaa1ee
children e2f467522651
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 # 20110429 <pankso@slitaz.org> - GNU gpl.
7 #
9 # Check if user is root.
10 if test $(id -u) != 0; then
11 echo -e "\nYou must be root to run `basename $0`!"
12 echo -e "Type su and root password to become super-user.\n"
13 exit 1
14 fi
16 get_messages()
17 {
18 [ -f "/etc/locale.conf" ] && . /etc/locale.conf
19 LANGUAGE=${LANG%_*}
20 [ "$LANG" = "C" ] && LANGUAGE="en_US"
21 case $LANGUAGE in
22 fr*)
23 RECONFIG_MSG="
24 Veuilliez fermer votre session et vous reloguer pour utiliser SliTaz \
25 avec la locale : $LANG" ;;
26 *)
27 RECONFIG_MSG="
28 Please logout of your current session and login again to use SliTaz \
29 with $LANG locale." ;;
30 esac
31 }
33 # Create symlink to translated files provide by SliTaz language pack,
34 # doc and config files.
35 link_language_files()
36 {
37 . /etc/locale.conf
38 LANGUAGE=${LANG%_*}
39 [ "$LANG" = "C" ] && LANGUAGE="en"
40 # Openbox menu in /usr/share/doc/slitaz
41 if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then
42 cd /etc/xdg/openbox && rm -f menu.xml
43 ln -s menu.$LANGUAGE.xml menu.xml
44 fi
45 # Documentation in /usr/share/doc/slitaz
46 if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then
47 cd /usr/share/doc/slitaz && rm -f index.html
48 ln -s index.$LANGUAGE.html index.html
49 fi
50 # SliTaz Software Manuals
51 for soft in tazpkg tazlito tazusb tazwok burnbox tazweb
52 do
53 if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then
54 cd /usr/share/doc/$soft && rm -f $soft.html
55 ln -s $soft.$LANGUAGE.html $soft.html
56 fi
57 done
58 }
60 # Locale name displayed.
61 get_locale_name()
62 {
63 for i in `ls -1 /usr/share/i18n/locales | grep ^[a-z][a-z]_[A-Z][A-Z]`
64 do
65 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
66 echo "$i Locale"
67 done
68 }
70 # We have no locale files in /usr/lib/locale by default. Run localedef in
71 # background to have a faster boot.
72 gen_utf8_locale()
73 {
74 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
75 }
77 # Dialog menu.
78 dialog_menu()
79 {
80 exec 3>&1
81 locale=`$DIALOG --clear \
82 --title " SliTaz language configuration " \
83 --menu "" 15 70 5 \
84 "en" "English" \
85 $(get_locale_name) \
86 2>&1 1>&3`
87 retval=$?
88 exec 3>&-
89 case $retval in
90 0)
91 continue ;;
92 1)
93 echo "Cancel pressed."
94 exit 0 ;;
95 255)
96 if test -n "$locale"; then
97 echo "$locale"
98 else
99 echo "ESC pressed."
100 exit 0
101 fi ;;
102 esac
103 # Default: C = English
104 [ "$locale" = "en" ] && locale="en_US"
105 [ -s /etc/locale.conf ] && RECONFIG="yes"
106 # System configuration
107 echo "LANG=$locale" > /etc/locale.conf
108 echo "LC_ALL=$locale" >> /etc/locale.conf
109 export LANG=$locale LC_ALL=$locale
110 gen_utf8_locale
111 get_messages
112 # If it's a reconfiguration give an info message.
113 if [ -n "$RECONFIG" ]; then
114 $DIALOG --clear \
115 --title " Information " \
116 --msgbox "$RECONFIG_MSG" 16 70
117 fi
118 }
120 case "$1" in
121 *_*)
122 # Execute functions (can be called from an other apps).
123 $1 ;;
124 list)
125 echo ""
126 locale -a
127 echo "" ;;
128 init)
129 # This command can be used to change system locale from cmdline.
130 locale=$2
131 echo "LANG=$locale" > /etc/locale.conf
132 echo "LC_ALL=$locale" >> /etc/locale.conf
133 gen_utf8_locale
134 link_language_files ;;
135 *)
136 : ${DIALOG=dialog}
137 dialog_menu
138 link_language_files ;;
139 esac
141 exit 0