slitaz-tools annotate tinyutils/tazlocale @ rev 930

Finish previous tiny edit
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Nov 25 00:41:01 2014 +0200 (2014-11-25)
parents 720dfc98b497
children 5d80f6fdbdb7
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 #
pascal@821 6 # Copyright (C) 2008-2014 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
al@813 11 export TEXTDOMAIN='slitaz-tools' #i18n
pankso@5 12
al@813 13 usage() {
al@813 14 newline
al@813 15 _ 'SliTaz GNU/Linux locale setting using dialog boxes.'
al@813 16
al@813 17 newline; boldify "$(_ 'Usage:')"
al@813 18 echo " tazlocale [$(_ 'option')]"
al@813 19
al@813 20 newline; boldify "$(_ 'Options:')"
al@813 21 optlist "\
al@813 22 info $(_ 'Show info about config file and current locale.')
al@813 23 list $(_ 'Show list of available locales.')"
al@813 24
al@813 25 newline
al@813 26 _ 'Any other option treated as locale - set locale (root).'
al@813 27 _ 'Display locale selecting dialog if no option given (root).'
al@813 28 newline
al@813 29 }
al@813 30
al@813 31 # Make symlink to file, substitute "%%" to "ll_CC", "ll" or "en" according to
paul@835 32 # current language settings and file existence
al@813 33 # (where "ll_CC" - full locale format (lang and country, and maybe, modifier).
al@813 34 make_i18n_link() {
al@813 35 if [ -d $(dirname ${1/.%%/}) ]; then
al@813 36 cd $(dirname ${1/.%%/})
al@813 37
al@813 38 if [ -e ${1/%%/$LANG} ]; then
al@813 39 ln -fs $(basename ${1/%%/$LANG}) ${1/.%%/}
al@813 40 else
al@813 41 if [ -e ${1/%%/$LANGUAGE} ]; then
al@813 42 ln -fs $(basename ${1/%%/$LANGUAGE}) ${1/.%%/}
al@813 43 else
al@813 44 ln -fs $(basename ${1/%%/en}) ${1/.%%/}
al@813 45 fi
al@813 46 fi
al@813 47 fi
al@813 48 }
pankso@622 49
paul@725 50 # Create symlink to translated files provided by SliTaz language pack,
pankso@338 51 # doc and config files.
al@813 52 link_language_files() {
pankso@338 53 . /etc/locale.conf
pankso@338 54 LANGUAGE=${LANG%_*}
al@813 55 [ "$LANG" == "POSIX" ] && LANGUAGE="en"
al@813 56 # Openbox menu
al@813 57 make_i18n_link /etc/xdg/openbox/menu.%%.xml
al@813 58 # Documentation
al@813 59 make_i18n_link /usr/share/doc/slitaz/index.%%.html
pankso@338 60 # SliTaz Software Manuals
al@813 61 for soft in tazpkg tazlito tazusb tazwok tazweb cookutils; do
al@813 62 make_i18n_link /usr/share/doc/$soft/$soft.%%.html
pankso@338 63 done
al@716 64 # SliTaz TazWeb "My Web Home"
al@813 65 make_i18n_link /usr/share/tazweb/home.%%.html
al@728 66 # SliTaz WebHome
al@813 67 make_i18n_link /usr/share/webhome/index.%%.html
al@813 68 # TazPanel Doc under www
al@813 69 make_i18n_link /var/www/tazpanel/doc/tazpanel.%%.html
pankso@622 70 # SliTaz Tools Manuals
al@813 71 for soft in burnbox tazinst; do
al@813 72 make_i18n_link /usr/share/doc/slitaz-tools/$soft.%%.html
pankso@622 73 done
pankso@338 74 }
pankso@338 75
pankso@170 76 # Locale name displayed.
al@813 77 get_locale_name() {
al@813 78 for i in $(ls -1 /usr/share/i18n/locales | grep [a-z]_[A-Z]); do
pankso@568 79 #desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
pankso@426 80 echo "$i Locale"
pankso@170 81 done
pankso@170 82 }
pankso@170 83
al@813 84 # We have no locale files in /usr/lib/locale by default.
al@813 85 # Run localedef in background to have a faster boot.
al@813 86 gen_utf8_locale() {
al@813 87 [ -e /usr/lib/locale/$locale ] || \
al@813 88 localedef -i $locale -c -f UTF-8 /usr/lib/locale/$locale &
pankso@426 89 }
pankso@426 90
pankso@749 91 # Config /etc/locale.conf
pankso@749 92 system_config() {
pankso@751 93 export LC_ALL=$locale
al@813 94 _n "Setting system locale to: $locale"
al@813 95 echo -e "LANG=$locale\nLC_ALL=$locale" > /etc/locale.conf
al@813 96 status
pankso@749 97 gen_utf8_locale
pankso@749 98 link_language_files
pankso@749 99 }
pankso@749 100
pankso@5 101 # Dialog menu.
al@813 102 dialog_menu() {
pankso@338 103 exec 3>&1
pankso@749 104 locale=$($DIALOG --clear \
pankso@837 105 --title "{ $(_n 'SliTaz language setting') }" \
pankso@837 106 --menu "" 20 72 14 \
pankso@170 107 "en" "English" \
pankso@170 108 $(get_locale_name) \
pankso@749 109 2>&1 1>&3)
pankso@338 110 retval=$?
pankso@338 111 exec 3>&-
pankso@338 112 case $retval in
pankso@622 113 0) continue ;;
pankso@622 114 1|255) exit 0 ;;
pankso@338 115 esac
al@728 116
pankso@752 117 # Default: POSIX = English
pankso@426 118 [ "$locale" = "en" ] && locale="en_US"
pankso@338 119 [ -s /etc/locale.conf ] && RECONFIG="yes"
al@728 120
pankso@338 121 # If it's a reconfiguration give an info message.
pankso@338 122 if [ -n "$RECONFIG" ]; then
pankso@751 123 export LC_ALL=$locale
al@813 124 msg=$(_n "\
pankso@622 125 Please logout of your current session and login again to use new locale.")
al@813 126 $DIALOG --clear --title " $(_n 'Information') " --msgbox "$msg" 16 70
pankso@338 127 fi
pankso@749 128 system_config
pankso@338 129 }
pankso@5 130
pankso@338 131 case "$1" in
al@813 132 --help|-h)
al@813 133 usage ;;
pankso@753 134 info)
al@813 135 optlist "\
al@813 136 $(_ 'Config file:') /etc/locale.conf
al@813 137 $(_ 'Current locale:') $LANG"
al@813 138 ;;
pankso@338 139 list)
al@813 140 list=
al@813 141 for i in $(ls -1 /usr/share/i18n/locales | grep '[a-z]_[A-Z]'); do
al@813 142 desc=$(fgrep -m1 title /usr/share/i18n/locales/$i | cut -d'"' -f2)
al@813 143 list="$list
al@813 144 $i $desc"
al@813 145 done
al@813 146 optlist "$list" ;;
pankso@749 147 "")
pankso@749 148 # No args: display Ncurses dialog.
pascal@916 149 : ${DIALOG=dialog --timeout 60}
al@813 150 check_root $@
pankso@749 151 dialog_menu ;;
pankso@749 152 *)
pankso@749 153 # Usage: tazlocale LANG_COUNTRY
pankso@749 154 locale=$1
al@813 155 check_root $@
al@813 156 system_config ;;
pankso@5 157 esac
pankso@5 158
pankso@5 159 exit 0