slitaz-tools view tinyutils/tazlocale @ rev 145

tazlocale: most rewrited and gen locale list automaticaly
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 17 19:06:33 2008 +0200 (2008-04-17)
parents 841f4dd95ea2
children c26b3dc5e83f
line source
1 #!/bin/sh
2 #
3 # Tazlocale: SliTaz GNU/Linux locale setting using dialog boxes.
4 # Configuration file is : /etc/locale.conf
5 #
6 # 20080417 <pankso@slitaz.org> - GNU gpl.
7 #
8 : ${DIALOG=dialog}
10 # Script functions.
11 status()
12 {
13 local CHECK=$?
14 echo -en "\\033[70G[ "
15 if [ $CHECK = 0 ]; then
16 echo -en "\\033[1;33mOK"
17 else
18 echo -en "\\033[1;31mFailed"
19 fi
20 echo -e "\\033[0;39m ]"
21 }
23 # Check if user is root.
24 #
25 if test $(id -u) != 0; then
26 echo -e "\nYou must be root to run `basename $0`!"
27 echo -e "Type su and root password to become super-user.\n"
28 exit 1
29 fi
31 # Dialog menu.
32 #
33 exec 3>&1
34 value=`$DIALOG --clear \
35 --title " SliTaz locale configuration " \
36 --menu \
37 "Select your language - Séléctionnez votre langue" 15 70 5 \
38 $(cd /usr/share/i18n/locales/; ls -1 [a-z][a-z]_* | awk '{ printf "%s Locale\n",$1,$2 }') \
39 2>&1 1>&3`
40 retval=$?
41 exec 3>&-
43 case $retval in
44 0)
45 continue ;;
46 1)
47 echo "Cancel pressed."
48 exit 0 ;;
49 255)
50 if test -n "$value"; then
51 echo "$value"
52 else
53 echo "ESC pressed."
54 exit 0
55 fi ;;
56 esac
58 LOCALE=$value
60 # Set charmaps, used files are in: /usr/share/i18n/charmaps
61 #
62 case $LOCALE in
63 # ISO-8859-1
64 de_*|en_*|es_*|fr_*|it_IT)
65 CHARMAP='ISO-8859-1' ;;
66 # ISO-8859-2
67 cs_*)
68 CHARMAP='ISO-8859-2' ;;
69 ru_*)
70 CHARMAP='KOI8-RU' ;;
71 *)
72 echo "Locale: $value specifications not yet implemeted... Sorry."
73 CHARMAP='ISO-8859-1'
74 LOCALE='en_US' ;;
75 esac
77 # System configuration
78 echo -n "Setting system locale to: $value "
79 localedef -i $LOCALE -c -f ISO-8859-1 $fs/usr/lib/locale/$LOCALE
80 status
81 echo -n "Creating configuration file: /etc/locale.conf"
82 echo "LANG=$LOCALE" > /etc/locale.conf
83 echo "LC_ALL=$LOCALE" >> /etc/locale.conf
84 status
86 if [ -f "/etc/locale.conf" ]; then
87 . /etc/locale.conf
88 export LANG LC_ALL
89 fi
91 exit 0