tazpanel annotate locale.cgi @ rev 605
Add de.po (thanks HGT)
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Sat Oct 15 16:49:13 2016 +0100 (2016-10-15) |
parents | 3117717c007d |
children | 26f60e49e3d5 |
rev | line source |
---|---|
al@452 | 1 #!/bin/sh |
al@452 | 2 # |
al@452 | 3 # Locale settings CGI interface. |
al@452 | 4 # |
al@452 | 5 # Copyright (C) 2015 SliTaz GNU/Linux - BSD License |
al@452 | 6 # |
al@452 | 7 |
al@452 | 8 |
al@452 | 9 # Common functions from libtazpanel |
al@452 | 10 |
al@452 | 11 . lib/libtazpanel |
al@452 | 12 get_config |
al@452 | 13 header |
al@452 | 14 |
al@501 | 15 TITLE=$(_ 'Locale') |
al@452 | 16 |
al@452 | 17 |
al@452 | 18 |
al@452 | 19 ############################# |
al@452 | 20 # Get info from locale file # |
al@452 | 21 ############################# |
al@452 | 22 |
al@452 | 23 get_locale_info() |
al@452 | 24 { |
al@452 | 25 # Commands like `LC_ALL=fr_FR locale -k LC_MEASUREMENT` will do the job |
paul@540 | 26 # only when your locale is generated and exists in the /usr/lib/locale. |
al@452 | 27 # Here we manually parse locale definition files from /usr/share/i18n/locales/. |
al@452 | 28 # Strange, bloated and not script-friendly format :( |
al@452 | 29 |
al@452 | 30 [ ! -e /usr/share/i18n/locales/$1 ] && return |
al@452 | 31 |
al@452 | 32 # Prepare file |
al@452 | 33 if [ ! -e /tmp/tazpanel-$1 ]; then |
al@452 | 34 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 |
al@452 | 35 fi |
al@452 | 36 |
al@452 | 37 local ANS=$(grep -e "^$2[ ]" /tmp/tazpanel-$1 | sed 's|^[^ \t][^ \t]* *||') |
al@452 | 38 if [ -z "$ANS" ]; then |
al@452 | 39 # Not found, then section is copied from other locale definition file... |
al@452 | 40 case $2 in |
al@452 | 41 measurement) |
al@452 | 42 section='LC_MEASUREMENT';; |
al@452 | 43 width|height) |
al@452 | 44 section='LC_PAPER';; |
al@452 | 45 currency_symbol|int_curr_symbol) |
al@452 | 46 section='LC_MONETARY';; |
al@452 | 47 day|abday|mon|abmon|d_t_fmt|d_fmt|t_fmt|am_pm|t_fmt_ampm|date_fmt) |
al@452 | 48 section='LC_TIME';; |
al@452 | 49 esac |
al@452 | 50 # Recursive call |
al@452 | 51 get_locale_info $(sed -n '/^'$section'/,/^END '$section'/p' /tmp/tazpanel-$1 | grep 'copy' | cut -d'"' -f2) $2 |
al@452 | 52 else |
al@452 | 53 case $2 in |
al@452 | 54 day|abday|mon|abmon|am_pm) # semicolon-separated list in double quotes |
al@452 | 55 echo "$ANS";; |
al@452 | 56 *) # single value in double qoutes |
al@452 | 57 echo "$ANS" | cut -d'"' -f2;; |
al@452 | 58 esac |
al@452 | 59 fi |
al@452 | 60 } |
al@452 | 61 |
al@452 | 62 |
al@452 | 63 # Get info from locale file about measurement system |
al@452 | 64 |
al@452 | 65 get_locale_info_measurement() |
al@452 | 66 { |
al@452 | 67 # faster to use pre-processed values |
al@452 | 68 case $1 in |
al@452 | 69 en_AG|en_US|es_PR|es_US|nl_AW|yi_US) _ 'US' ;; |
al@452 | 70 POSIX) ;; |
al@452 | 71 *) _ 'metric' ;; |
al@452 | 72 esac |
al@452 | 73 } |
al@452 | 74 |
al@452 | 75 |
al@452 | 76 # Get info from locale file about paper size |
al@452 | 77 |
al@452 | 78 get_locale_info_paper() |
al@452 | 79 { |
al@452 | 80 # faster to use pre-processed values |
al@452 | 81 case $1 in |
al@452 | 82 en_AG|en_US|es_PR|es_US|nl_AW|yi_US) echo '8½×11 (US Letter)';; |
al@452 | 83 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)';; |
al@452 | 84 POSIX) ;; |
al@452 | 85 *) echo '210×297 (A4)';; |
al@452 | 86 esac |
al@452 | 87 } |
al@452 | 88 |
al@452 | 89 |
al@452 | 90 # Get info from locale file about date and time format |
al@452 | 91 |
al@452 | 92 get_locale_info_date_time() |
al@452 | 93 { |
al@452 | 94 case $2 in |
al@452 | 95 c) get_locale_info $1 d_t_fmt ;; |
al@452 | 96 x) get_locale_info $1 d_fmt ;; |
al@452 | 97 X) get_locale_info $1 t_fmt ;; |
al@452 | 98 r) get_locale_info $1 t_fmt_ampm ;; |
al@452 | 99 *) get_locale_info $1 date_fmt ;; |
al@452 | 100 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;' |
al@452 | 101 |
al@452 | 102 } |
al@452 | 103 |
al@452 | 104 |
al@452 | 105 parse_date() |
al@452 | 106 { |
al@452 | 107 local weekday month day abday mon abmon rtime d_fmt t_fmt am_pm |
al@452 | 108 weekday=$(( $(date +%w) + 1 )) # 1=Sunday ... |
al@452 | 109 month=$(date +%-m) # 1=January ... |
al@452 | 110 day=$(get_locale_info $1 day | cut -d'"' -f$(( 2 * $weekday )) | sed 's|&|\\\&|g') # translated day of week |
al@452 | 111 abday=$(get_locale_info $1 abday | cut -d'"' -f$(( 2 * $weekday )) | sed 's|&|\\\&|g') # same, abbreviated |
al@452 | 112 mon=$(get_locale_info $1 mon | cut -d'"' -f$(( 2 * $month )) | sed 's|&|\\\&|g') # translated month |
al@452 | 113 abmon=$(get_locale_info $1 abmon | cut -d'"' -f$(( 2 * $month )) | sed 's|&|\\\&|g') # same, abbreviated |
al@452 | 114 # next %-codes expanded into other %-codes |
al@452 | 115 rtime=$(get_locale_info_date_time $1 r | sed 's|&|\\\&|g') # %r: 12-hour time |
al@452 | 116 d_fmt=$(get_locale_info_date_time $1 x | sed 's|&|\\\&|g') # %x: date |
al@452 | 117 t_fmt=$(get_locale_info_date_time $1 X | sed 's|&|\\\&|g') # %X: time |
al@452 | 118 |
al@452 | 119 case $(LC_ALL=POSIX date +%P) in # translated am/pm |
al@452 | 120 am) am_pm=$(get_locale_info $1 am_pm | cut -d'"' -f2 | sed 's|&|\\\&|g');; |
al@452 | 121 pm) am_pm=$(get_locale_info $1 am_pm | cut -d'"' -f4 | sed 's|&|\\\&|g');; |
al@452 | 122 esac |
al@452 | 123 |
al@452 | 124 # 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 |
al@452 | 125 # Note: %P=am/pm; %p=AM/PM. But here they the same because it is not a simple job to convert letters. |
al@452 | 126 echo "$2" | sed "s|%r|$rtime|; s|%x|$d_fmt|; s|%X|$t_fmt|; \ |
al@452 | 127 s|%OC|S(date +%OC)|; \ |
al@452 | 128 s|%Y|$(date +%Y)|; s|%y|$(date +%y )|; s|%Oy|$(date +%Oy)|; s|%Ey|$(date +%Ey)|; \ |
al@452 | 129 s|%m|$(date +%m)|; s|%-m|$(date +%-m)|; s|%Om|$(date +%Om)|; \ |
al@452 | 130 s|%d|$(date +%d)|; s|%-d|$(date +%-d)|; s|%Od|$(date +%Od)|; \ |
al@452 | 131 s|%e|$(date +%e)|; s|%-e|$(date +%-e)|; s|%Oe|$(date +%Oe)|; \ |
al@452 | 132 s|%F|$(date +%F)|; \ |
al@452 | 133 s|%H|$(date +%H)|; s|%OH|$(date +%OH)|; s|%k|$(date +%k)|; \ |
al@452 | 134 s|%I|$(date +%I)|; s|%OI|$(date +%OI)|; s|%l|$(date +%l)|; \ |
al@452 | 135 s|%M|$(date +%M)|; s|%OM|$(date +%OM)|; \ |
al@452 | 136 s|%S|$(date +%S)|; s|%OS|$(date +%OS)|; \ |
al@452 | 137 s|%R|$(date +%R)|; s|%T|$(date +%T )|; \ |
al@452 | 138 s|%Z|$(date +%Z)|; s|%z|$(date +%z )|; \ |
al@452 | 139 s|%t|\t|; \ |
al@452 | 140 s|%P|$am_pm|; s|%p|$am_pm|; s|%Op|$am_pm|; s|%A|$day|; s|%a|$abday|; s|%B|$mon|; s|%b|$abmon|;" |
al@452 | 141 |
al@452 | 142 } |
al@452 | 143 |
al@452 | 144 list_of() |
al@452 | 145 { |
al@452 | 146 cd /usr/share/i18n/locales |
al@452 | 147 #mon=$(date +%-m); monn=$(( $mon * 2 )) |
al@452 | 148 #echo "mon=\"$mon\" monn=\"$monn\"" |
al@452 | 149 |
al@452 | 150 cat <<EOT |
al@452 | 151 <table class="wide zebra filelist"> |
al@452 | 152 <thead> |
al@452 | 153 <tr><td>Locale</td> |
al@452 | 154 <td>Date format</td> |
al@452 | 155 <td>Native date</td> |
al@452 | 156 <td>Measurement</td> |
al@452 | 157 <td>Paper size</td> |
al@452 | 158 </tr> |
al@452 | 159 </thead> |
al@452 | 160 EOT |
al@452 | 161 |
al@452 | 162 for LOC in en_US fr_CA be_BY ca_IT el_CY fr_CH ru_RU ru_UA; do |
al@452 | 163 case $LOC in |
al@452 | 164 iso*|translit*) ;; |
al@452 | 165 *) |
al@452 | 166 #echo -e "$LOC:\t$(parse_date $LOC $(get_locale_info_date_time $LOC c | sed 's|&|\\\&|g'))";; |
al@498 | 167 FMT="$(get_locale_info_date_time $LOC x)" |
al@452 | 168 echo "<tr><td>$LOC</td><td>$FMT</td><td>" |
al@452 | 169 parse_date $LOC "$FMT" |
al@452 | 170 echo "</td><td>" |
al@452 | 171 get_locale_info_measurement $LOC |
al@452 | 172 echo "</td><td>" |
al@452 | 173 get_locale_info_paper $LOC |
al@452 | 174 echo "</td></tr>" |
al@452 | 175 ;; |
al@452 | 176 esac |
al@452 | 177 done |
al@452 | 178 echo '</table>' |
al@452 | 179 } |
al@452 | 180 |
al@452 | 181 |
al@452 | 182 |
al@452 | 183 |
al@452 | 184 |
al@452 | 185 # |
al@452 | 186 # Default xHTML content |
al@452 | 187 # |
al@452 | 188 |
al@452 | 189 xhtml_header |
al@452 | 190 check_root_tazpanel |
al@452 | 191 |
al@452 | 192 cat <<EOT |
al@452 | 193 <h2>Under construction!</h2> |
al@452 | 194 |
al@452 | 195 <section> |
al@452 | 196 <header>Current date and some i18n values in the different locales:</header> |
al@452 | 197 $(list_of) |
al@452 | 198 </section> |
al@452 | 199 EOT |
al@452 | 200 |
al@452 | 201 xhtml_footer |
al@452 | 202 exit 0 |