tazpanel diff locale.cgi @ rev 462
Fix "Confirm break", add Improvement script, tiny edits.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sat Apr 18 16:26:58 2015 +0300 (2015-04-18) |
parents | |
children | 470ab4241de5 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/locale.cgi Sat Apr 18 16:26:58 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|�|\&#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| | |g; s|%|%|g; s|,|,|g; s|-|-|g; s|.|.|g; s|/|/|g; s|:|:|g; s|A|A|g; s|B|B|g; s|C|C|g; s|F|F|g; s|H|H|g; s|I|I|g; s|M|M|g; s|O|O|g; s|R|R|g; s|S|S|g; s|T|T|g; s|X|X|g; s|Y|Y|g; s|Z|Z|g; s|a|a|g; s|b|b|g; s|e|e|g; s|d|d|g; s|k|k|g; s|m|m|g; s|n|n|g; s|o|o|g; s|p|p|g; s|r|r|g; s|t|t|g; s|x|x|g; s|y|y|g; s|z|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