slitaz-tools annotate tinyutils/tazlocale @ rev 728

tazlocale: added support for localizable webhome
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Apr 07 17:33:06 2012 +0300 (2012-04-07)
parents 29fe613b2eb6
children 433b4e383048
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@622 6 # 20110614 <pankso@slitaz.org> - GNU gpl.
pankso@5 7 #
pankso@5 8
pankso@622 9 # Internationalization
pankso@622 10 . /usr/bin/gettext.sh
pankso@622 11 TEXTDOMAIN='slitaz-tools'
pankso@622 12 export TEXTDOMAIN
pankso@622 13
pankso@5 14 # Check if user is root.
pankso@5 15 if test $(id -u) != 0; then
pankso@623 16 gettext "You must be root to run:"; echo " $(basename $0)"
pankso@622 17 gettext "Type su and root password to become super-user"; echo
pankso@145 18 exit 1
pankso@5 19 fi
pankso@5 20
paul@725 21 # Create symlink to translated files provided by SliTaz language pack,
pankso@338 22 # doc and config files.
pankso@338 23 link_language_files()
pankso@338 24 {
pankso@338 25 . /etc/locale.conf
pankso@338 26 LANGUAGE=${LANG%_*}
pankso@338 27 [ "$LANG" = "C" ] && LANGUAGE="en"
pankso@338 28 # Openbox menu in /usr/share/doc/slitaz
pankso@338 29 if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then
pankso@338 30 cd /etc/xdg/openbox && rm -f menu.xml
pankso@338 31 ln -s menu.$LANGUAGE.xml menu.xml
pankso@338 32 fi
pankso@338 33 # Documentation in /usr/share/doc/slitaz
pankso@338 34 if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then
pankso@338 35 cd /usr/share/doc/slitaz && rm -f index.html
pankso@338 36 ln -s index.$LANGUAGE.html index.html
pankso@338 37 fi
pankso@338 38 # SliTaz Software Manuals
pankso@622 39 for soft in tazpkg tazlito tazusb tazwok tazweb tazpanel
pankso@338 40 do
pankso@338 41 if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then
pankso@338 42 cd /usr/share/doc/$soft && rm -f $soft.html
pankso@338 43 ln -s $soft.$LANGUAGE.html $soft.html
pankso@338 44 fi
pankso@338 45 done
al@716 46 # SliTaz TazWeb "My Web Home"
al@716 47 if [ -f /usr/share/tazweb/home.$LANGUAGE.html ]; then
al@716 48 cd /usr/share/tazweb && rm -f home.html
al@716 49 ln -s home.$LANGUAGE.html home.html
al@716 50 fi
al@728 51 # SliTaz WebHome
al@728 52 if [ -f /usr/share/webhome/index.$LANGUAGE.html ]; then
al@728 53 cd /usr/share/webhome && rm -f index.html
al@728 54 ln -s index.$LANGUAGE.html index.html
al@728 55 fi
pankso@622 56 # SliTaz Tools Manuals
pankso@622 57 for soft in burnbox tazinst
pankso@622 58 do
pankso@622 59 if [ -f /usr/share/doc/slitaz-tools/$soft.$LANGUAGE.html ]; then
pankso@622 60 cd /usr/share/doc/slitaz-tools && rm -f $soft.html
pankso@622 61 ln -s $soft.$LANGUAGE.html $soft.html
pankso@622 62 fi
pankso@622 63 done
pankso@338 64 }
pankso@338 65
pankso@170 66 # Locale name displayed.
pankso@170 67 get_locale_name()
pankso@170 68 {
pankso@568 69 for i in `ls -1 /usr/share/i18n/locales | grep ^[a-z][a-z]_[A-Z][A-Z]`
pankso@170 70 do
pankso@568 71 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
pankso@426 72 echo "$i Locale"
pankso@170 73 done
pankso@170 74 }
pankso@170 75
pankso@426 76 # We have no locale files in /usr/lib/locale by default. Run localedef in
pankso@426 77 # background to have a faster boot.
pankso@426 78 gen_utf8_locale()
pankso@426 79 {
pankso@426 80 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
pankso@426 81 }
pankso@426 82
pankso@5 83 # Dialog menu.
pankso@338 84 dialog_menu()
pankso@338 85 {
pankso@338 86 exec 3>&1
pankso@426 87 locale=`$DIALOG --clear \
pankso@623 88 --title " $(gettext "SliTaz language configuration") " \
pankso@338 89 --menu "" 15 70 5 \
pankso@170 90 "en" "English" \
pankso@170 91 $(get_locale_name) \
pankso@5 92 2>&1 1>&3`
pankso@338 93 retval=$?
pankso@338 94 exec 3>&-
pankso@338 95 case $retval in
pankso@622 96 0) continue ;;
pankso@622 97 1|255) exit 0 ;;
pankso@338 98 esac
al@728 99
pankso@338 100 # Default: C = English
pankso@426 101 [ "$locale" = "en" ] && locale="en_US"
pankso@338 102 [ -s /etc/locale.conf ] && RECONFIG="yes"
al@728 103
pankso@338 104 # System configuration
pankso@426 105 echo "LANG=$locale" > /etc/locale.conf
pankso@426 106 echo "LC_ALL=$locale" >> /etc/locale.conf
pankso@426 107 export LANG=$locale LC_ALL=$locale
pankso@426 108 gen_utf8_locale
pankso@338 109 get_messages
al@728 110
pankso@338 111 # If it's a reconfiguration give an info message.
pankso@338 112 if [ -n "$RECONFIG" ]; then
pankso@622 113 msg=$(gettext "\
pankso@622 114 Please logout of your current session and login again to use new locale.")
pankso@338 115 $DIALOG --clear \
pankso@338 116 --title " Information " \
pankso@622 117 --msgbox "$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 list)
pankso@338 126 echo ""
pankso@338 127 locale -a
pankso@338 128 echo "" ;;
pankso@568 129 init)
pankso@568 130 # This command can be used to change system locale from cmdline.
pankso@568 131 locale=$2
pankso@568 132 echo "LANG=$locale" > /etc/locale.conf
pankso@568 133 echo "LC_ALL=$locale" >> /etc/locale.conf
pankso@568 134 gen_utf8_locale
pankso@568 135 link_language_files ;;
pankso@338 136 *)
pankso@426 137 : ${DIALOG=dialog}
pankso@338 138 dialog_menu
pankso@338 139 link_language_files ;;
pankso@5 140 esac
pankso@5 141
pankso@5 142 exit 0