slitaz-tools view tinyutils/tazlocale @ rev 338

tazlocale: Add support for i18n Slitaz files from locale pack
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 30 23:21:22 2009 +0200 (2009-04-30)
parents af65458ca488
children adf1e99ee3e8
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 # 20090428 <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 . /etc/locale.conf
19 LANGUAGE=${LANG%_*}
20 [ "$LANG" = "C" ] && LANGUAGE="en"
21 case $LANGUAGE in
22 fr)
23 RECONFIG_MSG="
24 Veuilliez fermer votre session et vous reloguer pour utiliser
25 SliTaz avec la locale : fr." ;;
26 *)
27 RECONFIG_MSG="
28 Please logout of your current session and login again to SliTaz
29 and locale : $LANGUAGE" ;;
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
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 `locale -a | grep "[a-z]_"`
64 do
65 name=`locale -a -v | grep -A 2 "locale: $i" | grep "title" | \
66 cut -d " " -f 7`
67 echo "$i $name"
68 done
69 }
71 # Dialog menu.
72 dialog_menu()
73 {
74 exec 3>&1
75 value=`$DIALOG --clear \
76 --title " SliTaz language configuration " \
77 --menu "" 15 70 5 \
78 "en" "English" \
79 $(get_locale_name) \
80 2>&1 1>&3`
81 retval=$?
82 exec 3>&-
83 case $retval in
84 0)
85 continue ;;
86 1)
87 echo "Cancel pressed."
88 exit 0 ;;
89 255)
90 if test -n "$value"; then
91 echo "$value"
92 else
93 echo "ESC pressed."
94 exit 0
95 fi ;;
96 esac
97 # Default: C = English
98 [ "$value" = "en" ] && value="C"
99 [ -s /etc/locale.conf ] && RECONFIG="yes"
100 # System configuration
101 echo "LANG=$value" > /etc/locale.conf
102 echo "LC_ALL=$value" >> /etc/locale.conf
103 export LANG=$value LC_ALL=$value
104 get_messages
105 # If it's a reconfiguration give an info message.
106 if [ -n "$RECONFIG" ]; then
107 $DIALOG --clear \
108 --title " Information " \
109 --msgbox "\n$RECONFIG_MSG\n" 16 70
110 fi
111 }
113 case "$1" in
114 *_*)
115 # Execute functions (can be called from an other apps).
116 $1 ;;
117 link-files)
118 link_language_files ;;
119 dialog)
120 : ${DIALOG=dialog}
121 dialog_menu
122 link_language_files ;;
123 list)
124 echo ""
125 locale -a
126 echo "" ;;
127 *)
128 : ${DIALOG=tazdialog}
129 export ICON="preferences-desktop-locale"
130 dialog_menu
131 link_language_files ;;
132 esac
134 exit 0