slitaz-tools view tinyutils/tazlocale @ rev 625

Gettextize setmixer and make pot
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 14 22:47:24 2011 +0200 (2011-06-14)
parents e2f467522651
children ed15185975c2
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 provide 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 Tools Manuals
47 for soft in burnbox tazinst
48 do
49 if [ -f /usr/share/doc/slitaz-tools/$soft.$LANGUAGE.html ]; then
50 cd /usr/share/doc/slitaz-tools && rm -f $soft.html
51 ln -s $soft.$LANGUAGE.html $soft.html
52 fi
53 done
54 }
56 # Locale name displayed.
57 get_locale_name()
58 {
59 for i in `ls -1 /usr/share/i18n/locales | grep ^[a-z][a-z]_[A-Z][A-Z]`
60 do
61 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
62 echo "$i Locale"
63 done
64 }
66 # We have no locale files in /usr/lib/locale by default. Run localedef in
67 # background to have a faster boot.
68 gen_utf8_locale()
69 {
70 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
71 }
73 # Dialog menu.
74 dialog_menu()
75 {
76 exec 3>&1
77 locale=`$DIALOG --clear \
78 --title " $(gettext "SliTaz language configuration") " \
79 --menu "" 15 70 5 \
80 "en" "English" \
81 $(get_locale_name) \
82 2>&1 1>&3`
83 retval=$?
84 exec 3>&-
85 case $retval in
86 0) continue ;;
87 1|255) exit 0 ;;
88 esac
90 # Default: C = English
91 [ "$locale" = "en" ] && locale="en_US"
92 [ -s /etc/locale.conf ] && RECONFIG="yes"
94 # System configuration
95 echo "LANG=$locale" > /etc/locale.conf
96 echo "LC_ALL=$locale" >> /etc/locale.conf
97 export LANG=$locale LC_ALL=$locale
98 gen_utf8_locale
99 get_messages
101 # If it's a reconfiguration give an info message.
102 if [ -n "$RECONFIG" ]; then
103 msg=$(gettext "\
104 Please logout of your current session and login again to use new locale.")
105 $DIALOG --clear \
106 --title " Information " \
107 --msgbox "$msg" 16 70
108 fi
109 }
111 case "$1" in
112 *_*)
113 # Execute functions (can be called from an other apps).
114 $1 ;;
115 list)
116 echo ""
117 locale -a
118 echo "" ;;
119 init)
120 # This command can be used to change system locale from cmdline.
121 locale=$2
122 echo "LANG=$locale" > /etc/locale.conf
123 echo "LC_ALL=$locale" >> /etc/locale.conf
124 gen_utf8_locale
125 link_language_files ;;
126 *)
127 : ${DIALOG=dialog}
128 dialog_menu
129 link_language_files ;;
130 esac
132 exit 0