slitaz-tools annotate tinyutils/tazlocale @ rev 939

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