slitaz-tools rev 338

tazlocale: Add support for i18n Slitaz files from locale pack
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 30 23:21:22 2009 +0200 (2009-04-30)
parents e3a4a4478e2e
children 777b680060ec
files tinyutils/tazlocale
line diff
     1.1 --- a/tinyutils/tazlocale	Tue Apr 28 10:50:19 2009 +0200
     1.2 +++ b/tinyutils/tazlocale	Thu Apr 30 23:21:22 2009 +0200
     1.3 @@ -3,32 +3,60 @@
     1.4  # Tazlocale: SliTaz GNU/Linux locale setting using dialog boxes.
     1.5  # Configuration file is : /etc/locale.conf
     1.6  #
     1.7 -# 20080417 <pankso@slitaz.org> - GNU gpl.
     1.8 +# 20090428 <pankso@slitaz.org> - GNU gpl.
     1.9  #
    1.10 -: ${DIALOG=tazdialog}
    1.11 -export ICON="preferences-desktop-locale"
    1.12 -
    1.13 -# Script functions.
    1.14 -status()
    1.15 -{
    1.16 -	local CHECK=$?
    1.17 -	echo -en "\\033[70G[ "
    1.18 -	if [ $CHECK = 0 ]; then
    1.19 -		echo -en "\\033[1;33mOK"
    1.20 -	else
    1.21 -		echo -en "\\033[1;31mFailed"
    1.22 -	fi
    1.23 -	echo -e "\\033[0;39m ]"
    1.24 -}
    1.25  
    1.26  # Check if user is root.
    1.27 -#
    1.28  if test $(id -u) != 0; then
    1.29  	echo -e "\nYou must be root to run `basename $0`!"
    1.30  	echo -e "Type su and root password to become super-user.\n"
    1.31  	exit 1
    1.32  fi
    1.33  
    1.34 +get_messages()
    1.35 +{
    1.36 +	. /etc/locale.conf
    1.37 +	LANGUAGE=${LANG%_*}
    1.38 +	[ "$LANG" = "C" ] && LANGUAGE="en"
    1.39 +	case $LANGUAGE in
    1.40 +		fr)
    1.41 +			RECONFIG_MSG="
    1.42 +Veuilliez fermer votre session et vous reloguer pour utiliser
    1.43 +SliTaz avec la locale : fr." ;;
    1.44 +		*)
    1.45 +			RECONFIG_MSG="
    1.46 +Please logout of your current session and login again to SliTaz
    1.47 +and locale : $LANGUAGE" ;;
    1.48 +	esac
    1.49 +}
    1.50 +
    1.51 +# Create symlink to translated files provide by SliTaz language pack,
    1.52 +# doc and config files.
    1.53 +link_language_files()
    1.54 +{
    1.55 +	. /etc/locale.conf
    1.56 +	LANGUAGE=${LANG%_*}
    1.57 +	[ "$LANG" = "C" ] && LANGUAGE="en"
    1.58 +	# Openbox menu in /usr/share/doc/slitaz
    1.59 +	if [ -f /etc/xdg/openbox/menu.$LANGUAGE.xml ]; then
    1.60 +		cd /etc/xdg/openbox && rm -f menu.xml
    1.61 +		ln -s menu.$LANGUAGE.xml menu.xml
    1.62 +	fi
    1.63 +	# Documentation in /usr/share/doc/slitaz
    1.64 +	if [ -f /usr/share/doc/slitaz/index.$LANGUAGE.html ]; then
    1.65 +		cd /usr/share/doc/slitaz && rm -f index.html
    1.66 +		ln -s index.$LANGUAGE.html index.html
    1.67 +	fi
    1.68 +	# SliTaz Software Manuals
    1.69 +	for soft in tazpkg tazlito tazusb tazwok
    1.70 +	do
    1.71 +		if [ -f /usr/share/doc/$soft/$soft.$LANGUAGE.html ]; then
    1.72 +			cd /usr/share/doc/$soft && rm -f $soft.html
    1.73 +			ln -s $soft.$LANGUAGE.html $soft.html
    1.74 +		fi
    1.75 +	done
    1.76 +}
    1.77 +
    1.78  # Locale name displayed.
    1.79  get_locale_name()
    1.80  {
    1.81 @@ -41,52 +69,66 @@
    1.82  }
    1.83  
    1.84  # Dialog menu.
    1.85 -#
    1.86 -exec 3>&1
    1.87 -value=`$DIALOG  --clear \
    1.88 -	--title " SliTaz locale configuration " \
    1.89 -	--menu \
    1.90 -"\nSelect your language - Séléctionnez votre langue" 15 70 5 \
    1.91 +dialog_menu()
    1.92 +{
    1.93 +	exec 3>&1
    1.94 +	value=`$DIALOG  --clear \
    1.95 +	--title " SliTaz language configuration " \
    1.96 +	--menu "" 15 70 5 \
    1.97  "en" "English" \
    1.98  $(get_locale_name) \
    1.99  2>&1 1>&3`
   1.100 -retval=$?
   1.101 -exec 3>&-
   1.102 +	retval=$?
   1.103 +	exec 3>&-
   1.104 +	case $retval in
   1.105 +		0)
   1.106 +			continue ;;
   1.107 +		1)
   1.108 +			echo "Cancel pressed."
   1.109 +			exit 0 ;;
   1.110 +		255)
   1.111 +			if test -n "$value"; then
   1.112 +				echo "$value"
   1.113 +			else
   1.114 +				echo "ESC pressed."
   1.115 +				exit 0
   1.116 +			fi ;;
   1.117 +	esac
   1.118 +	# Default: C = English
   1.119 +	[ "$value" = "en" ] && value="C"
   1.120 +	[ -s /etc/locale.conf ] && RECONFIG="yes"
   1.121 +	# System configuration
   1.122 +	echo "LANG=$value" > /etc/locale.conf
   1.123 +	echo "LC_ALL=$value" >> /etc/locale.conf
   1.124 +	export LANG=$value LC_ALL=$value
   1.125 +	get_messages
   1.126 +	# If it's a reconfiguration give an info message.
   1.127 +	if [ -n "$RECONFIG" ]; then
   1.128 +		$DIALOG --clear \
   1.129 +			--title " Information " \
   1.130 +			--msgbox "\n$RECONFIG_MSG\n" 16 70
   1.131 +	fi
   1.132 +}
   1.133  
   1.134 -case $retval in
   1.135 -	0)
   1.136 -		continue ;;
   1.137 -	1)
   1.138 -		echo "Cancel pressed."
   1.139 -		exit 0 ;;
   1.140 -	255)
   1.141 -	if test -n "$value"; then
   1.142 -		echo "$value"
   1.143 -	else
   1.144 -		echo "ESC pressed."
   1.145 -		exit 0
   1.146 -	fi ;;
   1.147 +case "$1" in
   1.148 +	*_*)
   1.149 +		# Execute functions (can be called from an other apps).
   1.150 +		$1 ;;
   1.151 +	link-files)
   1.152 +		link_language_files ;;
   1.153 +	dialog)
   1.154 +		: ${DIALOG=dialog}
   1.155 +		dialog_menu
   1.156 +		link_language_files ;;
   1.157 +	list)
   1.158 +		echo ""
   1.159 +		locale -a
   1.160 +		echo "" ;;
   1.161 +	*)
   1.162 +		: ${DIALOG=tazdialog}
   1.163 +		export ICON="preferences-desktop-locale"
   1.164 +		dialog_menu
   1.165 +		link_language_files ;;
   1.166  esac
   1.167  
   1.168 -# Default: C = English
   1.169 -if [ "$value" = "en" ]; then
   1.170 -	value='C'
   1.171 -fi
   1.172 -
   1.173 -# If it's a reconfiguration give an info message.
   1.174 -if [ -s /etc/locale.conf ]; then
   1.175 -	$DIALOG --clear \
   1.176 -		--title " Locale setting information\n " \
   1.177 -		--msgbox "
   1.178 -Please logout of your current session and login again to use $value
   1.179 -locale.\n" 16 70
   1.180 -fi
   1.181 -
   1.182 -# System configuration
   1.183 -echo "LANG=$value" > /etc/locale.conf
   1.184 -echo "LC_ALL=$value" >> /etc/locale.conf
   1.185 -
   1.186 -. /etc/locale.conf
   1.187 -export LANG LC_ALL
   1.188 -
   1.189  exit 0