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