tazpanel rev 452

Move some code from settings.cgi to new locale.cgi (under construction).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 10 15:35:35 2015 +0300 (2015-04-10)
parents b1687097358f
children 61395bbfe889
files locale.cgi settings.cgi styles/default/base.css
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/locale.cgi	Fri Apr 10 15:35:35 2015 +0300
     1.3 @@ -0,0 +1,202 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Locale settings CGI interface.
     1.7 +#
     1.8 +# Copyright (C) 2015 SliTaz GNU/Linux - BSD License
     1.9 +#
    1.10 +
    1.11 +
    1.12 +# Common functions from libtazpanel
    1.13 +
    1.14 +. lib/libtazpanel
    1.15 +get_config
    1.16 +header
    1.17 +
    1.18 +TITLE=$(_ 'TazPanel - Locale')
    1.19 +
    1.20 +
    1.21 +
    1.22 +#############################
    1.23 +# Get info from locale file #
    1.24 +#############################
    1.25 +
    1.26 +get_locale_info()
    1.27 +{
    1.28 +	# Commands like `LC_ALL=fr_FR locale -k LC_MEASUREMENT` will do the job
    1.29 +	#   only when your locale is generated and exists in the /usr/lib/locale.
    1.30 +	# Here we manually parse locale definition files from /usr/share/i18n/locales/.
    1.31 +	# Strange, bloated and not script-friendly format :(
    1.32 +
    1.33 +	[ ! -e /usr/share/i18n/locales/$1 ] && return
    1.34 +
    1.35 +	# Prepare file
    1.36 +	if [ ! -e /tmp/tazpanel-$1 ]; then
    1.37 +		sed 's|^[ \t]*||;/^%/d;/^comment_char/d;/^escape_char/d' /usr/share/i18n/locales/$1 | tr '\n' '&' | sed 's|/&||g' | tr '&' '\n' | sed 's|<U\([0-9a-fA-F]*\)>|\&#x\1;|g' | sed 's|&#x00|\&#x|g' > /tmp/tazpanel-$1
    1.38 +	fi
    1.39 +
    1.40 +	local ANS=$(grep -e "^$2[ 	]" /tmp/tazpanel-$1 | sed 's|^[^ \t][^ \t]* *||')
    1.41 +	if [ -z "$ANS" ]; then
    1.42 +		# Not found, then section is copied from other locale definition file...
    1.43 +		case $2 in
    1.44 +			measurement)
    1.45 +				section='LC_MEASUREMENT';;
    1.46 +			width|height)
    1.47 +				section='LC_PAPER';;
    1.48 +			currency_symbol|int_curr_symbol)
    1.49 +				section='LC_MONETARY';;
    1.50 +			day|abday|mon|abmon|d_t_fmt|d_fmt|t_fmt|am_pm|t_fmt_ampm|date_fmt)
    1.51 +				section='LC_TIME';;
    1.52 +		esac
    1.53 +		# Recursive call
    1.54 +		get_locale_info $(sed -n '/^'$section'/,/^END '$section'/p' /tmp/tazpanel-$1 | grep 'copy' | cut -d'"' -f2) $2
    1.55 +	else
    1.56 +		case $2 in
    1.57 +			day|abday|mon|abmon|am_pm)		# semicolon-separated list in double quotes
    1.58 +				echo "$ANS";;
    1.59 +			*)		# single value in double qoutes
    1.60 +				echo "$ANS" | cut -d'"' -f2;;
    1.61 +		esac
    1.62 +	fi
    1.63 +}
    1.64 +
    1.65 +
    1.66 +# Get info from locale file about measurement system
    1.67 +
    1.68 +get_locale_info_measurement()
    1.69 +{
    1.70 +	# faster to use pre-processed values
    1.71 +	case $1 in
    1.72 +		en_AG|en_US|es_PR|es_US|nl_AW|yi_US) _ 'US' ;;
    1.73 +		POSIX) ;;
    1.74 +		*) _ 'metric' ;;
    1.75 +	esac
    1.76 +}
    1.77 +
    1.78 +
    1.79 +# Get info from locale file about paper size
    1.80 +
    1.81 +get_locale_info_paper()
    1.82 +{
    1.83 +	# faster to use pre-processed values
    1.84 +	case $1 in
    1.85 +		en_AG|en_US|es_PR|es_US|nl_AW|yi_US) echo '8½×11 (US Letter)';;
    1.86 +		en_CA|en_PH|es_CL|es_CO|es_CR|es_GT|es_MX|es_NI|es_PA|es_SV|es_VE|fil_PH|fr_CA|ik_CA|iu_CA|shs_CA|tl_PH) echo '216×279 (US Letter)';;
    1.87 +		POSIX) ;;
    1.88 +		*) echo '210×297 (A4)';;
    1.89 +	esac
    1.90 +}
    1.91 +
    1.92 +
    1.93 +# Get info from locale file about date and time format
    1.94 +
    1.95 +get_locale_info_date_time()
    1.96 +{
    1.97 +	case $2 in
    1.98 +		c) get_locale_info $1 d_t_fmt ;;
    1.99 +		x) get_locale_info $1 d_fmt ;;
   1.100 +		X) get_locale_info $1 t_fmt ;;
   1.101 +		r) get_locale_info $1 t_fmt_ampm ;;
   1.102 +		*) get_locale_info $1 date_fmt ;;
   1.103 +	esac | sed 's|&#x20;| |g; s|&#x25;|%|g; s|&#x2C;|,|g; s|&#x2D;|-|g; s|&#x2E;|.|g; s|&#x2F;|/|g; s|&#x3A;|:|g; s|&#x41;|A|g; s|&#x42;|B|g; s|&#x43;|C|g; s|&#x46;|F|g; s|&#x48;|H|g; s|&#x49;|I|g; s|&#x4D;|M|g; s|&#x4F;|O|g; s|&#x52;|R|g; s|&#x53;|S|g; s|&#x54;|T|g; s|&#x58;|X|g; s|&#x59;|Y|g; s|&#x5A;|Z|g; s|&#x61;|a|g; s|&#x62;|b|g; s|&#x65;|e|g; s|&#x64;|d|g; s|&#x6B;|k|g; s|&#x6D;|m|g; s|&#x6E;|n|g; s|&#x6F;|o|g; s|&#x70;|p|g; s|&#x72;|r|g; s|&#x74;|t|g; s|&#x78;|x|g; s|&#x79;|y|g; s|&#x7A;|z|g;'
   1.104 +
   1.105 +}
   1.106 +
   1.107 +
   1.108 +parse_date()
   1.109 +{
   1.110 +	local weekday month day abday mon abmon rtime d_fmt t_fmt am_pm
   1.111 +	weekday=$(( $(date +%w) + 1 ))											# 1=Sunday ...
   1.112 +	  month=$(date +%-m)													# 1=January ...
   1.113 +	  day=$(get_locale_info $1   day | cut -d'"' -f$(( 2 * $weekday )) | sed 's|&|\\\&|g')	# translated day of week
   1.114 +	abday=$(get_locale_info $1 abday | cut -d'"' -f$(( 2 * $weekday )) | sed 's|&|\\\&|g')	#   same, abbreviated
   1.115 +	  mon=$(get_locale_info $1   mon | cut -d'"' -f$(( 2 * $month   )) | sed 's|&|\\\&|g')	# translated month
   1.116 +	abmon=$(get_locale_info $1 abmon | cut -d'"' -f$(( 2 * $month   )) | sed 's|&|\\\&|g')	#   same, abbreviated
   1.117 +	# next %-codes expanded into other %-codes
   1.118 +	rtime=$(get_locale_info_date_time $1 r | sed 's|&|\\\&|g')									# %r: 12-hour time
   1.119 +	d_fmt=$(get_locale_info_date_time $1 x | sed 's|&|\\\&|g')									# %x: date
   1.120 +	t_fmt=$(get_locale_info_date_time $1 X | sed 's|&|\\\&|g')									# %X: time
   1.121 +
   1.122 +	case $(LC_ALL=POSIX date +%P) in										# translated am/pm
   1.123 +		am) am_pm=$(get_locale_info $1 am_pm | cut -d'"' -f2 | sed 's|&|\\\&|g');;
   1.124 +		pm) am_pm=$(get_locale_info $1 am_pm | cut -d'"' -f4 | sed 's|&|\\\&|g');;
   1.125 +	esac
   1.126 +
   1.127 +	# r x X | OC | Y y Oy Ey | m -m Om | d -d Od | e -e Oe | F | H OH k | I OI l | M OM | S OS | R T | Z z | t | P p Op A a B b
   1.128 +	# Note: %P=am/pm; %p=AM/PM. But here they the same because it is not a simple job to convert letters.
   1.129 +	echo "$2" | sed "s|%r|$rtime|; s|%x|$d_fmt|; s|%X|$t_fmt|; \
   1.130 +		s|%OC|S(date +%OC)|; \
   1.131 +		s|%Y|$(date +%Y)|; s|%y|$(date  +%y )|; s|%Oy|$(date +%Oy)|; s|%Ey|$(date +%Ey)|; \
   1.132 +		s|%m|$(date +%m)|; s|%-m|$(date +%-m)|; s|%Om|$(date +%Om)|; \
   1.133 +		s|%d|$(date +%d)|; s|%-d|$(date +%-d)|; s|%Od|$(date +%Od)|; \
   1.134 +		s|%e|$(date +%e)|; s|%-e|$(date +%-e)|; s|%Oe|$(date +%Oe)|; \
   1.135 +		s|%F|$(date +%F)|; \
   1.136 +		s|%H|$(date +%H)|; s|%OH|$(date +%OH)|; s|%k|$(date +%k)|; \
   1.137 +		s|%I|$(date +%I)|; s|%OI|$(date +%OI)|; s|%l|$(date +%l)|; \
   1.138 +		s|%M|$(date +%M)|; s|%OM|$(date +%OM)|; \
   1.139 +		s|%S|$(date +%S)|; s|%OS|$(date +%OS)|; \
   1.140 +		s|%R|$(date +%R)|; s|%T|$(date  +%T )|; \
   1.141 +		s|%Z|$(date +%Z)|; s|%z|$(date  +%z )|; \
   1.142 +		s|%t|\t|; \
   1.143 +		s|%P|$am_pm|; s|%p|$am_pm|; s|%Op|$am_pm|; s|%A|$day|; s|%a|$abday|; s|%B|$mon|; s|%b|$abmon|;"
   1.144 +
   1.145 +}
   1.146 +
   1.147 +list_of()
   1.148 +{
   1.149 +	cd /usr/share/i18n/locales
   1.150 +	#mon=$(date +%-m); monn=$(( $mon * 2 ))
   1.151 +	#echo "mon=\"$mon\" monn=\"$monn\""
   1.152 +
   1.153 +	cat <<EOT
   1.154 +<table class="wide zebra filelist">
   1.155 +	<thead>
   1.156 +		<tr><td>Locale</td>
   1.157 +			<td>Date format</td>
   1.158 +			<td>Native date</td>
   1.159 +			<td>Measurement</td>
   1.160 +			<td>Paper size</td>
   1.161 +		</tr>
   1.162 +	</thead>
   1.163 +EOT
   1.164 +
   1.165 +for LOC in en_US fr_CA be_BY ca_IT el_CY fr_CH ru_RU ru_UA; do
   1.166 +	case $LOC in
   1.167 +		iso*|translit*) ;;
   1.168 +		*)
   1.169 +			#echo -e "$LOC:\t$(parse_date $LOC $(get_locale_info_date_time $LOC c | sed 's|&|\\\&|g'))";;
   1.170 +			FMT="$(get_locale_info_date_time $LOC c)"
   1.171 +			echo "<tr><td>$LOC</td><td>$FMT</td><td>"
   1.172 +			parse_date $LOC "$FMT"
   1.173 +			echo "</td><td>"
   1.174 +			get_locale_info_measurement $LOC
   1.175 +			echo "</td><td>"
   1.176 +			get_locale_info_paper $LOC
   1.177 +			echo "</td></tr>"
   1.178 +			;;
   1.179 +	esac
   1.180 +done
   1.181 +	echo '</table>'
   1.182 +}
   1.183 +
   1.184 +
   1.185 +
   1.186 +
   1.187 +
   1.188 +#
   1.189 +# Default xHTML content
   1.190 +#
   1.191 +
   1.192 +xhtml_header
   1.193 +check_root_tazpanel
   1.194 +
   1.195 +cat <<EOT
   1.196 +<h2>Under construction!</h2>
   1.197 +
   1.198 +<section>
   1.199 +	<header>Current date and some i18n values in the different locales:</header>
   1.200 +	$(list_of)
   1.201 +</section>
   1.202 +EOT
   1.203 +
   1.204 +xhtml_footer
   1.205 +exit 0
     2.1 --- a/settings.cgi	Fri Apr 10 12:13:52 2015 +0200
     2.2 +++ b/settings.cgi	Fri Apr 10 15:35:35 2015 +0300
     2.3 @@ -30,153 +30,6 @@
     2.4  }
     2.5  
     2.6  
     2.7 -#############################
     2.8 -# Get info from locale file #
     2.9 -#############################
    2.10 -
    2.11 -get_locale_info()
    2.12 -{
    2.13 -	# Commands like `LC_ALL=fr_FR locale -k LC_MEASUREMENT` will do the job
    2.14 -	#   only when your locale is generated and exists in the /usr/lib/locale.
    2.15 -	# Here we manually parse locale definition files from /usr/share/i18n/locales/.
    2.16 -	# Strange, bloated and not script-friendly format :(
    2.17 -
    2.18 -	[ ! -e /usr/share/i18n/locales/$1 ] && return
    2.19 -
    2.20 -	# Prepare file
    2.21 -	if [ ! -e /tmp/tazpanel-$1 ]; then
    2.22 -		sed 's|^[ \t]*||;/^%/d;/^comment_char/d;/^escape_char/d' /usr/share/i18n/locales/$1 | tr '\n' '&' | sed 's|/&||g' | tr '&' '\n' | sed 's|<U\([0-9a-fA-F]*\)>|\&#x\1;|g' | sed 's|&#x00|\&#x|g' > /tmp/tazpanel-$1
    2.23 -	fi
    2.24 -
    2.25 -	local ANS=$(grep -e "^$2[ 	]" /tmp/tazpanel-$1 | sed 's|^[^ \t][^ \t]* *||')
    2.26 -	if [ -z "$ANS" ]; then
    2.27 -		# Not found, then section is copied from other locale definition file...
    2.28 -		case $2 in
    2.29 -			measurement)
    2.30 -				section='LC_MEASUREMENT';;
    2.31 -			width|height)
    2.32 -				section='LC_PAPER';;
    2.33 -			currency_symbol|int_curr_symbol)
    2.34 -				section='LC_MONETARY';;
    2.35 -			day|abday|mon|abmon|d_t_fmt|d_fmt|t_fmt|am_pm|t_fmt_ampm|date_fmt)
    2.36 -				section='LC_TIME';;
    2.37 -		esac
    2.38 -		# Recursive call
    2.39 -		get_locale_info $(sed -n '/^'$section'/,/^END '$section'/p' /tmp/tazpanel-$1 | grep 'copy' | cut -d'"' -f2) $2
    2.40 -	else
    2.41 -		case $2 in
    2.42 -			day|abday|mon|abmon|am_pm)		# semicolon-separated list in double quotes
    2.43 -				echo "$ANS";;
    2.44 -			*)		# single value in double qoutes
    2.45 -				echo "$ANS" | cut -d'"' -f2;;
    2.46 -		esac
    2.47 -	fi
    2.48 -}
    2.49 -
    2.50 -
    2.51 -# Get info from locale file about measurement system
    2.52 -
    2.53 -get_locale_info_measurement()
    2.54 -{
    2.55 -	# faster to use pre-processed values
    2.56 -	case $1 in
    2.57 -		en_AG|en_US|es_PR|es_US|nl_AW|yi_US) _ 'US' ;;
    2.58 -		POSIX) ;;
    2.59 -		*) _ 'metric' ;;
    2.60 -	esac
    2.61 -}
    2.62 -
    2.63 -
    2.64 -# Get info from locale file about paper size
    2.65 -
    2.66 -get_locale_info_paper()
    2.67 -{
    2.68 -	# faster to use pre-processed values
    2.69 -	case $1 in
    2.70 -		en_AG|en_US|es_PR|es_US|nl_AW|yi_US) echo '8½×11 (US Letter)';;
    2.71 -		en_CA|en_PH|es_CL|es_CO|es_CR|es_GT|es_MX|es_NI|es_PA|es_SV|es_VE|fil_PH|fr_CA|ik_CA|iu_CA|shs_CA|tl_PH) echo '216×279 (US Letter)';;
    2.72 -		POSIX) ;;
    2.73 -		*) echo '210×297 (A4)';;
    2.74 -	esac
    2.75 -}
    2.76 -
    2.77 -
    2.78 -# Get info from locale file about date and time format
    2.79 -
    2.80 -get_locale_info_date_time()
    2.81 -{
    2.82 -	case $2 in
    2.83 -		c) get_locale_info $1 d_t_fmt ;;
    2.84 -		x) get_locale_info $1 d_fmt ;;
    2.85 -		X) get_locale_info $1 t_fmt ;;
    2.86 -		r) get_locale_info $1 t_fmt_ampm ;;
    2.87 -		*) get_locale_info $1 date_fmt ;;
    2.88 -	esac | sed 's|&#x20;| |g; s|&#x25;|%|g; s|&#x2C;|,|g; s|&#x2D;|-|g; s|&#x2E;|.|g; s|&#x2F;|/|g; s|&#x3A;|:|g; s|&#x41;|A|g; s|&#x42;|B|g; s|&#x43;|C|g; s|&#x46;|F|g; s|&#x48;|H|g; s|&#x49;|I|g; s|&#x4D;|M|g; s|&#x4F;|O|g; s|&#x52;|R|g; s|&#x53;|S|g; s|&#x54;|T|g; s|&#x58;|X|g; s|&#x59;|Y|g; s|&#x5A;|Z|g; s|&#x61;|a|g; s|&#x62;|b|g; s|&#x65;|e|g; s|&#x64;|d|g; s|&#x6B;|k|g; s|&#x6D;|m|g; s|&#x6E;|n|g; s|&#x6F;|o|g; s|&#x70;|p|g; s|&#x72;|r|g; s|&#x74;|t|g; s|&#x78;|x|g; s|&#x79;|y|g; s|&#x7A;|z|g;'
    2.89 -
    2.90 -}
    2.91 -
    2.92 -
    2.93 -parse_date()
    2.94 -{
    2.95 -	local weekday month day abday mon abmon rtime d_fmt t_fmt am_pm
    2.96 -	weekday=$(( $(date +%w) + 1 ))											# 1=Sunday ...
    2.97 -	  month=$(date +%-m)													# 1=January ...
    2.98 -	  day=$(get_locale_info $1   day | cut -d'"' -f$(( 2 * $weekday )) | sed 's|&|\\\&|g')	# translated day of week
    2.99 -	abday=$(get_locale_info $1 abday | cut -d'"' -f$(( 2 * $weekday )) | sed 's|&|\\\&|g')	#   same, abbreviated
   2.100 -	  mon=$(get_locale_info $1   mon | cut -d'"' -f$(( 2 * $month   )) | sed 's|&|\\\&|g')	# translated month
   2.101 -	abmon=$(get_locale_info $1 abmon | cut -d'"' -f$(( 2 * $month   )) | sed 's|&|\\\&|g')	#   same, abbreviated
   2.102 -	# next %-codes expanded into other %-codes
   2.103 -	rtime=$(get_locale_info_date_time $1 r | sed 's|&|\\\&|g')									# %r: 12-hour time
   2.104 -	d_fmt=$(get_locale_info_date_time $1 x | sed 's|&|\\\&|g')									# %x: date
   2.105 -	t_fmt=$(get_locale_info_date_time $1 X | sed 's|&|\\\&|g')									# %X: time
   2.106 -
   2.107 -	case $(LC_ALL=POSIX date +%P) in										# translated am/pm
   2.108 -		am) am_pm=$(get_locale_info $1 am_pm | cut -d'"' -f2 | sed 's|&|\\\&|g');;
   2.109 -		pm) am_pm=$(get_locale_info $1 am_pm | cut -d'"' -f4 | sed 's|&|\\\&|g');;
   2.110 -	esac
   2.111 -
   2.112 -	# r x X | OC | Y y Oy Ey | m -m Om | d -d Od | e -e Oe | F | H OH k | I OI l | M OM | S OS | R T | Z z | t | P p Op A a B b
   2.113 -	# Note: %P=am/pm; %p=AM/PM. But here they the same because it is not a simple job to convert letters.
   2.114 -	echo "$2" | sed "s|%r|$rtime|; s|%x|$d_fmt|; s|%X|$t_fmt|; \
   2.115 -		s|%OC|S(date +%OC)|; \
   2.116 -		s|%Y|$(date +%Y)|; s|%y|$(date  +%y )|; s|%Oy|$(date +%Oy)|; s|%Ey|$(date +%Ey)|; \
   2.117 -		s|%m|$(date +%m)|; s|%-m|$(date +%-m)|; s|%Om|$(date +%Om)|; \
   2.118 -		s|%d|$(date +%d)|; s|%-d|$(date +%-d)|; s|%Od|$(date +%Od)|; \
   2.119 -		s|%e|$(date +%e)|; s|%-e|$(date +%-e)|; s|%Oe|$(date +%Oe)|; \
   2.120 -		s|%F|$(date +%F)|; \
   2.121 -		s|%H|$(date +%H)|; s|%OH|$(date +%OH)|; s|%k|$(date +%k)|; \
   2.122 -		s|%I|$(date +%I)|; s|%OI|$(date +%OI)|; s|%l|$(date +%l)|; \
   2.123 -		s|%M|$(date +%M)|; s|%OM|$(date +%OM)|; \
   2.124 -		s|%S|$(date +%S)|; s|%OS|$(date +%OS)|; \
   2.125 -		s|%R|$(date +%R)|; s|%T|$(date  +%T )|; \
   2.126 -		s|%Z|$(date +%Z)|; s|%z|$(date  +%z )|; \
   2.127 -		s|%t|\t|; \
   2.128 -		s|%P|$am_pm|; s|%p|$am_pm|; s|%Op|$am_pm|; s|%A|$day|; s|%a|$abday|; s|%B|$mon|; s|%b|$abmon|;"
   2.129 -
   2.130 -}
   2.131 -
   2.132 -list_of()
   2.133 -{
   2.134 -	cd /usr/share/i18n/locales
   2.135 -	#mon=$(date +%-m); monn=$(( $mon * 2 ))
   2.136 -	#echo "mon=\"$mon\" monn=\"$monn\""
   2.137 -
   2.138 -	echo '<pre>'
   2.139 -for LOC in be_BY ca_IT el_CY fr_CH ru_RU ru_UA; do
   2.140 -	case $LOC in
   2.141 -		iso*|translit*) ;;
   2.142 -		*)
   2.143 -			#echo -e "$LOC:\t$(parse_date $LOC $(get_locale_info_date_time $LOC c | sed 's|&|\\\&|g'))";;
   2.144 -			FMT="$(get_locale_info_date_time $LOC c)"
   2.145 -			echo -e "$LOC:\t$FMT"
   2.146 -			parse_date $LOC "$FMT"
   2.147 -			echo;;
   2.148 -	esac
   2.149 -done
   2.150 -	echo '</pre>'
   2.151 -}
   2.152 -
   2.153 -
   2.154  
   2.155  
   2.156  
     3.1 --- a/styles/default/base.css	Fri Apr 10 12:13:52 2015 +0200
     3.2 +++ b/styles/default/base.css	Fri Apr 10 15:35:35 2015 +0300
     3.3 @@ -337,6 +337,7 @@
     3.4  pre { margin: 0; padding: 0; color: CaptionText; }
     3.5  
     3.6  .pre-main { margin: 16px 0; }
     3.7 +.pre-wrap { white-space: pre-wrap; }
     3.8  
     3.9  
    3.10