slitaz-tools annotate tinyutils/tazlocale @ rev 977

tazlocale: no /usr/share/i18n/locales in base
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 21 17:36:09 2016 +0200 (2016-05-21)
parents 3e742c2981ea
children c9f9186f0093
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@943 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
pascal@977 92 locale_names() {
pascal@977 93 [ -d /usr/share/i18n/locales ] &&
pascal@977 94 ls -1 /usr/share/i18n/locales | grep [a-z]_[A-Z]
pascal@977 95 }
pascal@977 96
al@813 97 get_locale_name() {
pascal@977 98 for i in $(locale_names); do
al@961 99 echo -n "$i "
al@961 100 desc=$(grep ^title /usr/share/i18n/locales/$i | cut -d '"' -f 2)
al@961 101 if [ -n "$desc" ]; then
al@961 102 echo "$desc" | tr -c '[A-Za-z0-9\n]' '_'
al@961 103 else
al@961 104 echo "Locale"
al@961 105 fi
pankso@170 106 done
pankso@170 107 }
pankso@170 108
al@939 109
al@813 110 # We have no locale files in /usr/lib/locale by default.
al@813 111 # Run localedef in background to have a faster boot.
al@939 112
al@813 113 gen_utf8_locale() {
al@961 114 if [ ! -d "/usr/lib/locale/$locale.UTF-8" ]; then
al@961 115 localedef -i "$locale" -c -f 'UTF-8' "/usr/lib/locale/$locale.UTF-8" &
al@961 116 fi
pankso@426 117 }
pankso@426 118
al@939 119
pankso@749 120 # Config /etc/locale.conf
al@939 121
pankso@749 122 system_config() {
al@961 123 # If locale not defined: show error and exit
al@961 124 ls "/usr/share/i18n/locales/$locale" >/dev/null || return
al@961 125 export LC_ALL="$locale.UTF-8"
al@961 126 action 'Setting system locale to: %s' "$locale.UTF-8"
al@961 127 echo -e "LANG=$locale.UTF-8\nLC_ALL=$locale.UTF-8" > /etc/locale.conf
al@813 128 status
pankso@749 129 gen_utf8_locale
pankso@749 130 link_language_files
al@961 131 # Clean TazPanel cached headers in old language
al@961 132 [ -n "$(which tazpanel)" ] && tazpanel cc
pankso@749 133 }
pankso@749 134
al@939 135
pankso@5 136 # Dialog menu.
al@939 137
al@813 138 dialog_menu() {
pankso@338 139 exec 3>&1
pankso@749 140 locale=$($DIALOG --clear \
pankso@837 141 --title "{ $(_n 'SliTaz language setting') }" \
pankso@837 142 --menu "" 20 72 14 \
pankso@170 143 "en" "English" \
pankso@170 144 $(get_locale_name) \
pankso@749 145 2>&1 1>&3)
pankso@338 146 retval=$?
pankso@338 147 exec 3>&-
pankso@338 148 case $retval in
pankso@622 149 0) continue ;;
pankso@622 150 1|255) exit 0 ;;
pankso@338 151 esac
al@728 152
al@943 153 # Default: POSIX => English
al@943 154 [ "$locale" = 'en' ] && locale='en_US'
al@943 155 [ -s /etc/locale.conf ] && RECONFIG='yes'
al@728 156
pankso@338 157 # If it's a reconfiguration give an info message.
pankso@338 158 if [ -n "$RECONFIG" ]; then
pankso@751 159 export LC_ALL=$locale
al@813 160 msg=$(_n "\
pankso@622 161 Please logout of your current session and login again to use new locale.")
al@813 162 $DIALOG --clear --title " $(_n 'Information') " --msgbox "$msg" 16 70
pankso@338 163 fi
pankso@749 164 system_config
pankso@338 165 }
pankso@5 166
pankso@338 167 case "$1" in
al@813 168 --help|-h)
al@813 169 usage ;;
pankso@753 170 info)
al@961 171 . /etc/locale.conf
al@943 172 _ 'Config file: %s' '/etc/locale.conf'
al@943 173 _ 'Current locale: %s' "$LANG"
al@813 174 ;;
pankso@338 175 list)
al@813 176 list=
pascal@977 177 for i in $(locale_names); do
al@813 178 desc=$(fgrep -m1 title /usr/share/i18n/locales/$i | cut -d'"' -f2)
al@813 179 list="$list
al@813 180 $i $desc"
al@813 181 done
al@813 182 optlist "$list" ;;
pankso@749 183 "")
pankso@749 184 # No args: display Ncurses dialog.
pascal@916 185 : ${DIALOG=dialog --timeout 60}
al@813 186 check_root $@
pankso@749 187 dialog_menu ;;
pankso@749 188 *)
pankso@749 189 # Usage: tazlocale LANG_COUNTRY
pankso@749 190 locale=$1
al@813 191 check_root $@
al@813 192 system_config ;;
pankso@5 193 esac
pankso@5 194
pankso@5 195 exit 0