slitaz-tools view tinyutils/tazlocale @ rev 752

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