slitaz-tools view tinyutils/tazlocale @ rev 390
Add desktop file for Documentation --> GNU GPL
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Oct 01 21:38:06 2009 +0200 (2009-10-01) |
parents | 4e661d6dced9 |
children | 6017afdaa1ee |
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="Veuilliez fermer votre session et vous
24 reloguer pour utiliser SliTaz avec la locale : fr." ;;
25 *)
26 RECONFIG_MSG="Please logout of your current session and
27 login again to use SliTaz with $LANGUAGE locale." ;;
28 esac
29 }
31 # Create symlink to translated files provide by SliTaz language pack,
32 # doc and config files.
33 link_language_files()
34 {
35 . /etc/locale.conf
36 LANGUAGE=${LANG%_*}
37 [ "$LANG" = "C" ] && LANGUAGE="en"
38 # Openbox menu in /usr/share/doc/slitaz
39 if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then
40 cd /etc/xdg/openbox && rm -f menu.xml
41 ln -s menu.$LANGUAGE.xml menu.xml
42 fi
43 # Documentation in /usr/share/doc/slitaz
44 if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then
45 cd /usr/share/doc/slitaz && rm -f index.html
46 ln -s index.$LANGUAGE.html index.html
47 fi
48 # SliTaz Software Manuals
49 for soft in tazpkg tazlito tazusb tazwok
50 do
51 if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then
52 cd /usr/share/doc/$soft && rm -f $soft.html
53 ln -s $soft.$LANGUAGE.html $soft.html
54 fi
55 done
56 }
58 # Locale name displayed.
59 get_locale_name()
60 {
61 for i in `locale -a | grep "[a-z]_"`
62 do
63 name=`locale -a -v | grep -A 2 "locale: $i" | grep "title" | \
64 cut -d " " -f 7`
65 echo "$i $name"
66 done
67 }
69 # Dialog menu.
70 dialog_menu()
71 {
72 exec 3>&1
73 value=`$DIALOG --clear \
74 --title " SliTaz language configuration " \
75 --menu "" 15 70 5 \
76 "en" "English" \
77 $(get_locale_name) \
78 2>&1 1>&3`
79 retval=$?
80 exec 3>&-
81 case $retval in
82 0)
83 continue ;;
84 1)
85 echo "Cancel pressed."
86 exit 0 ;;
87 255)
88 if test -n "$value"; then
89 echo "$value"
90 else
91 echo "ESC pressed."
92 exit 0
93 fi ;;
94 esac
95 # Default: C = English
96 [ "$value" = "en" ] && value="C"
97 [ -s /etc/locale.conf ] && RECONFIG="yes"
98 # System configuration
99 echo "LANG=$value" > /etc/locale.conf
100 echo "LC_ALL=$value" >> /etc/locale.conf
101 export LANG=$value LC_ALL=$value
102 get_messages
103 # If it's a reconfiguration give an info message.
104 if [ -n "$RECONFIG" ]; then
105 $DIALOG --clear \
106 --title " Information " \
107 --msgbox "$RECONFIG_MSG" 16 70
108 fi
109 }
111 case "$1" in
112 *_*)
113 # Execute functions (can be called from an other apps).
114 $1 ;;
115 link-files)
116 link_language_files ;;
117 dialog)
118 : ${DIALOG=dialog}
119 dialog_menu
120 link_language_files ;;
121 list)
122 echo ""
123 locale -a
124 echo "" ;;
125 *)
126 : ${DIALOG=tazdialog}
127 export ICON="preferences-desktop-locale"
128 dialog_menu
129 link_language_files ;;
130 esac
132 exit 0