slitaz-tools annotate tinyutils/tazlocale @ rev 491
slitaz-installer: add tiny web boot support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Jul 05 16:15:05 2010 +0200 (2010-07-05) |
parents | adf1e99ee3e8 |
children | 513cf2248bf4 |
rev | line source |
---|---|
pankso@5 | 1 #!/bin/sh |
pankso@5 | 2 # |
pankso@5 | 3 # Tazlocale: SliTaz GNU/Linux locale setting using dialog boxes. |
pankso@5 | 4 # Configuration file is : /etc/locale.conf |
pankso@5 | 5 # |
pankso@426 | 6 # 20100201 <pankso@slitaz.org> - GNU gpl. |
pankso@5 | 7 # |
pankso@5 | 8 |
pankso@5 | 9 # Check if user is root. |
pankso@5 | 10 if test $(id -u) != 0; then |
pankso@145 | 11 echo -e "\nYou must be root to run `basename $0`!" |
pankso@145 | 12 echo -e "Type su and root password to become super-user.\n" |
pankso@145 | 13 exit 1 |
pankso@5 | 14 fi |
pankso@5 | 15 |
pankso@338 | 16 get_messages() |
pankso@338 | 17 { |
pankso@426 | 18 [ -f "/etc/locale.conf" ] && . /etc/locale.conf |
pankso@338 | 19 LANGUAGE=${LANG%_*} |
pankso@426 | 20 [ "$LANG" = "C" ] && LANGUAGE="en_US" |
pankso@338 | 21 case $LANGUAGE in |
pankso@426 | 22 fr*) |
pankso@426 | 23 RECONFIG_MSG=" |
pankso@426 | 24 Veuilliez fermer votre session et vous reloguer pour utiliser SliTaz \ |
pankso@426 | 25 avec la locale : $LANG" ;; |
pankso@338 | 26 *) |
pankso@426 | 27 RECONFIG_MSG=" |
pankso@426 | 28 Please logout of your current session and login again to use SliTaz \ |
pankso@426 | 29 with $LANG locale." ;; |
pankso@338 | 30 esac |
pankso@338 | 31 } |
pankso@338 | 32 |
pankso@338 | 33 # Create symlink to translated files provide by SliTaz language pack, |
pankso@338 | 34 # doc and config files. |
pankso@338 | 35 link_language_files() |
pankso@338 | 36 { |
pankso@338 | 37 . /etc/locale.conf |
pankso@338 | 38 LANGUAGE=${LANG%_*} |
pankso@338 | 39 [ "$LANG" = "C" ] && LANGUAGE="en" |
pankso@338 | 40 # Openbox menu in /usr/share/doc/slitaz |
pankso@338 | 41 if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then |
pankso@338 | 42 cd /etc/xdg/openbox && rm -f menu.xml |
pankso@338 | 43 ln -s menu.$LANGUAGE.xml menu.xml |
pankso@338 | 44 fi |
pankso@338 | 45 # Documentation in /usr/share/doc/slitaz |
pankso@338 | 46 if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then |
pankso@338 | 47 cd /usr/share/doc/slitaz && rm -f index.html |
pankso@338 | 48 ln -s index.$LANGUAGE.html index.html |
pankso@338 | 49 fi |
pankso@338 | 50 # SliTaz Software Manuals |
pankso@338 | 51 for soft in tazpkg tazlito tazusb tazwok |
pankso@338 | 52 do |
pankso@338 | 53 if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then |
pankso@338 | 54 cd /usr/share/doc/$soft && rm -f $soft.html |
pankso@338 | 55 ln -s $soft.$LANGUAGE.html $soft.html |
pankso@338 | 56 fi |
pankso@338 | 57 done |
pankso@338 | 58 } |
pankso@338 | 59 |
pankso@170 | 60 # Locale name displayed. |
pankso@170 | 61 get_locale_name() |
pankso@170 | 62 { |
pankso@426 | 63 for i in `ls -1 /usr/share/i18n/locales/ | grep ^[a-z][a-z]_[A-Z][A-Z]` |
pankso@170 | 64 do |
pankso@426 | 65 #name=`locale -a -v | grep -A 2 "locale: $i" | grep "title" | \ |
pankso@426 | 66 # cut -d " " -f 7` |
pankso@426 | 67 echo "$i Locale" |
pankso@170 | 68 done |
pankso@170 | 69 } |
pankso@170 | 70 |
pankso@426 | 71 # We have no locale files in /usr/lib/locale by default. Run localedef in |
pankso@426 | 72 # background to have a faster boot. |
pankso@426 | 73 gen_utf8_locale() |
pankso@426 | 74 { |
pankso@426 | 75 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale & |
pankso@426 | 76 } |
pankso@426 | 77 |
pankso@5 | 78 # Dialog menu. |
pankso@338 | 79 dialog_menu() |
pankso@338 | 80 { |
pankso@338 | 81 exec 3>&1 |
pankso@426 | 82 locale=`$DIALOG --clear \ |
pankso@338 | 83 --title " SliTaz language configuration " \ |
pankso@338 | 84 --menu "" 15 70 5 \ |
pankso@170 | 85 "en" "English" \ |
pankso@170 | 86 $(get_locale_name) \ |
pankso@5 | 87 2>&1 1>&3` |
pankso@338 | 88 retval=$? |
pankso@338 | 89 exec 3>&- |
pankso@338 | 90 case $retval in |
pankso@338 | 91 0) |
pankso@338 | 92 continue ;; |
pankso@338 | 93 1) |
pankso@338 | 94 echo "Cancel pressed." |
pankso@338 | 95 exit 0 ;; |
pankso@338 | 96 255) |
pankso@426 | 97 if test -n "$locale"; then |
pankso@426 | 98 echo "$locale" |
pankso@338 | 99 else |
pankso@338 | 100 echo "ESC pressed." |
pankso@338 | 101 exit 0 |
pankso@338 | 102 fi ;; |
pankso@338 | 103 esac |
pankso@338 | 104 # Default: C = English |
pankso@426 | 105 [ "$locale" = "en" ] && locale="en_US" |
pankso@338 | 106 [ -s /etc/locale.conf ] && RECONFIG="yes" |
pankso@338 | 107 # System configuration |
pankso@426 | 108 echo "LANG=$locale" > /etc/locale.conf |
pankso@426 | 109 echo "LC_ALL=$locale" >> /etc/locale.conf |
pankso@426 | 110 export LANG=$locale LC_ALL=$locale |
pankso@426 | 111 gen_utf8_locale |
pankso@338 | 112 get_messages |
pankso@338 | 113 # If it's a reconfiguration give an info message. |
pankso@338 | 114 if [ -n "$RECONFIG" ]; then |
pankso@338 | 115 $DIALOG --clear \ |
pankso@338 | 116 --title " Information " \ |
paul@352 | 117 --msgbox "$RECONFIG_MSG" 16 70 |
pankso@338 | 118 fi |
pankso@338 | 119 } |
pankso@5 | 120 |
pankso@338 | 121 case "$1" in |
pankso@338 | 122 *_*) |
pankso@338 | 123 # Execute functions (can be called from an other apps). |
pankso@338 | 124 $1 ;; |
pankso@338 | 125 link-files) |
pankso@338 | 126 link_language_files ;; |
pankso@338 | 127 list) |
pankso@338 | 128 echo "" |
pankso@338 | 129 locale -a |
pankso@338 | 130 echo "" ;; |
pankso@338 | 131 *) |
pankso@426 | 132 : ${DIALOG=dialog} |
pankso@338 | 133 dialog_menu |
pankso@338 | 134 link_language_files ;; |
pankso@5 | 135 esac |
pankso@5 | 136 |
pankso@5 | 137 exit 0 |