website rev 1089
i18n.php: add scripts to auto-generate table
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Jul 27 13:59:05 2012 +0000 (2012-07-27) |
parents | ab542c939cab |
children | d4e390bc3a1c |
files | humans.txt i18n.php lib/i18n-info.php lib/i18n-info.sh |
line diff
1.1 --- a/humans.txt Fri Jul 27 10:55:31 2012 +0200 1.2 +++ b/humans.txt Fri Jul 27 13:59:05 2012 +0000 1.3 @@ -1,1 +1,1 @@ 1.4 -The SliTaz project was originated by Christophe lincoln and is developed by many contributors, see http://people.slitaz.org/ 1.5 +The SliTaz project was originated by Christophe Lincoln and is developed by many contributors, see http://people.slitaz.org/
2.1 --- a/i18n.php Fri Jul 27 10:55:31 2012 +0200 2.2 +++ b/i18n.php Fri Jul 27 13:59:05 2012 +0000 2.3 @@ -182,6 +182,9 @@ 2.4 menu translations. 2.5 --> 2.6 2.7 +<?php require_once("lib/i18n-info.php"); ?> 2.8 +<!-- ?php get_info(); ? --> 2.9 + 2.10 <table> 2.11 <thead class="thead"> 2.12 <tr><td>Project</td>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/lib/i18n-info.php Fri Jul 27 13:59:05 2012 +0000 3.3 @@ -0,0 +1,15 @@ 3.4 +<?php 3.5 + 3.6 +// Build table with i18n info on the SliTaz projects 3.7 +function get_info() { 3.8 + $infofile = '/var/cache/slitaz/website/i18n.html'; 3.9 + if ( ! file_exists("$infofile")) { 3.10 + echo "Can't show info!\nSorry..."; 3.11 + } 3.12 + else { 3.13 + $content = file_get_contents("$infofile"); 3.14 + echo "$content"; 3.15 + } 3.16 +} 3.17 + 3.18 +?>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/lib/i18n-info.sh Fri Jul 27 13:59:05 2012 +0000 4.3 @@ -0,0 +1,216 @@ 4.4 +#!/bin/sh 4.5 + 4.6 +# for english po statistics using `msgfmt --statistics` 4.7 +LC_ALL=C; export LC_ALL 4.8 + 4.9 +HG_URL="http://hg.slitaz.org" 4.10 +INFO_FILE="/var/cache/slitaz/website/i18n.html" 4.11 +mkdir -p "/var/cache/slitaz/website" 4.12 +touch "${INFO_FILE}.new" 4.13 +echo "" > "${INFO_FILE}.new" 4.14 + 4.15 +# echo to file 4.16 +echof() 4.17 +{ 4.18 + echo "$@" >> "${INFO_FILE}.new" 4.19 +} 4.20 + 4.21 +# print table cells with 'pot' and 'po's 4.22 +out_pot_po() 4.23 +{ 4.24 + TMP_PO="/tmp/i18n.po" 4.25 + # get all links to files in folder 4.26 + LINKS=$(wget "$HG_URL/$PROJ_BASE/$PROJ_PODIR/" -q -O - | \ 4.27 + grep -A 1 "filename" | \ 4.28 + grep "href" | \ 4.29 + sed 's|.*"\([^"]*\)".*|http://hg.slitaz.org\1|g' | \ 4.30 + sed 's|/file/[^/]*/|/raw-file/tip/|g') 4.31 + # get link to 'pot' and print cell 4.32 + LINK_POT=$(echo "$LINKS" | grep -e '\.pot$') 4.33 + 4.34 + echof " 4.35 + <td class=\"pot\"> 4.36 + <a href=\"$LINK_POT\"> 4.37 + $(echo $LINK_POT | sed 's|.*/\([^/]*\.pot\)$|\1|')</a></td> 4.38 + <td class=\"po\">" 4.39 + 4.40 + # process 'po's 4.41 + IFS=" 4.42 +" 4.43 + for FILE in $(echo "$LINKS" | grep -e '.po$'); do 4.44 + # temp download 4.45 + wget $FILE -q -O $TMP_PO 4.46 + # get stats 4.47 + STAT=$(msgfmt --statistics $TMP_PO 2>&1 | sed 's|[^0-9 ]||g') 4.48 + rm $TMP_PO 4.49 + # language; number of translated and untranslated entries 4.50 + LNG=$(echo $FILE | sed 's|.*/\([^/]*\)\.po$|\1|') 4.51 + TRAN=$(echo $STAT | cut -d" " -f1) 4.52 + UNTR=$(($(echo $STAT | awk '{print $2}') + 0)) 4.53 + # percents done 4.54 + PCNT=$(($TRAN * 100 / ($TRAN + $UNTR))) 4.55 + echof " <a href=\"$FILE\">$LNG<hr/>${PCNT}%</a>" 4.56 + done 4.57 + echof " </td>" 4.58 +} 4.59 + 4.60 + 4.61 +# print table cell with html documentations 4.62 +out_doc() 4.63 +{ 4.64 + # get all links to files in folder 4.65 + LINKS=$(wget "$HG_URL/$PROJ_BASE/$PROJ_DOCDIR/" -q -O - | \ 4.66 + grep -A 1 "filename" | \ 4.67 + grep "href" | \ 4.68 + sed 's|.*"\([^"]*\)".*|http://hg.slitaz.org\1|g' | \ 4.69 + sed 's|/file/[^/]*/|/raw-file/tip/|g') 4.70 + 4.71 + echof " <td class=\"docs\">" 4.72 + 4.73 + IFS=" 4.74 +" 4.75 + # get name of subproject, example: subproject 'tazusb-box' from 'tazusb' 4.76 + SUB_PROJ=$(echo "$PROJ_PODIR" | sed 's|.*/\(.*\)|\1|') 4.77 + for DOCUMENT in $(echo "$LINKS" | grep -e '.html$'); do 4.78 + # strip project and subproject names from doc filename 4.79 + NAME_DOC=$(echo $DOCUMENT | \ 4.80 + sed 's|.*/\([^/]*\)\.html$|\1|' | \ 4.81 + sed 's|'$PROJ_BASE'\.||; s|'$SUB_PROJ'\.||') 4.82 + # first part of filename, example faq.en -> faq 4.83 + NAME_DOC1=$(echo $NAME_DOC | cut -d"." -f1) 4.84 + # second part of filename, faq.en -> en 4.85 + NAME_DOC2=$(echo $NAME_DOC | cut -d"." -f2) 4.86 + # if filename have only [lang] then rename it to doc.[lang] 4.87 + if [ "x$NAME_DOC2" == "x" ]; then 4.88 + NAME_DOC2=$NAME_DOC1 4.89 + NAME_DOC1="doc" 4.90 + fi 4.91 + # not print 'linked' common documents, only localized ones 4.92 + # (often link [project].html pointed to [project].en.html) 4.93 + if [ "$NAME_DOC" != "$SUB_PROJ" ] && [ "$NAME_DOC" != "$PROJ_BASE" ]; then 4.94 + echof " <a href=\"$DOCUMENT\">$NAME_DOC1<br/>$NAME_DOC2</a>" 4.95 + fi 4.96 + done 4.97 + echof " </td>" 4.98 +} 4.99 + 4.100 + 4.101 +# print table cell with link to .desktop files 4.102 +out_app() 4.103 +{ 4.104 + APP_DIR="$HG_URL/$PROJ_BASE/file/tip/$PROJ_APPDIR" 4.105 + PAGE=$(wget $APP_DIR -q -O -) 4.106 + LINKS=$(echo "$PAGE" | grep -A 1 "filename" | grep "href" | wc -l) 4.107 + # plural form 4.108 + if [ "$LINKS" == "1" ]; then 4.109 + APP_TEXT="1<br/>item" 4.110 + else 4.111 + APP_TEXT="$LINKS<br/>items" 4.112 + fi 4.113 + 4.114 + # rowspan: folder with desktop files is one for project 4.115 + # combine all subprojects 4.116 + echof " <td class=\"desk\"$ROWSPAN><a href=\"$APP_DIR\">$APP_TEXT</a></td>" 4.117 +} 4.118 + 4.119 + 4.120 + 4.121 +# standard path to folder with 'pot' and 'po's 4.122 +S="file/tip/po" 4.123 +# standard path to doc folder 4.124 +D="file/tip/doc" 4.125 + 4.126 +# list of all processed projects; fields description: 4.127 +# [1]: Human readable project name (once) 4.128 +# [2]: Project base: http://hg.slitaz.org/[2] 4.129 +# [3]: Spanned cells (number or empty) 4.130 +# [4]: Pot&po folder: http://hg.slitaz.org/[2]/[4]/ 4.131 +# [5]: Docs folder: http://hg.slitaz.org/[2]/[5]/ 4.132 +# [6]: Apps folder: http://hg.slitaz.org/[2]/file/tip/[6]/ 4.133 +PROJ_LIST=" 4.134 +SliTaz Base Files|slitaz-base-files||$S||rootfs/usr/share/applications 4.135 +pkgs.slitaz.org|slitaz-forge/file/tip/pkgs||po|| 4.136 +SliTaz Pizza|slitaz-pizza||$S|$D| 4.137 +SliTaz Tools|slitaz-tools|5|$S/slitaz-boxes||applications 4.138 +|slitaz-tools||$S/slitaz-tools|| 4.139 +|slitaz-tools||$S/tazbox|| 4.140 +|slitaz-tools||$S/tazdrop|| 4.141 +|slitaz-tools||$S/tazinst|$D| 4.142 +SSFS|ssfs|2|$S/server||data 4.143 +|ssfs||$S/ssfs|| 4.144 +TazBug|tazbug||$S||data 4.145 +TazLito|tazlito||$S/tazlito-wiz|$D|applications 4.146 +TazPanel|tazpanel||$S|$D|data 4.147 +TazPkg|tazpkg|2|$S/tazpkg|$D|applications 4.148 +|tazpkg||$S/tazpkg-notify|| 4.149 +TazUsb|tazusb|2|$S/tazusb|$D|applications 4.150 +|tazusb||$S/tazusb-box||" 4.151 + 4.152 +# print table header 4.153 +echof " 4.154 +<table> 4.155 + <thead class=\"thead\"> 4.156 + <tr><td>Project</td> 4.157 + <td>POT file</td> 4.158 + <td>PO files</td> 4.159 + <td>Docs</td> 4.160 + <td>Menu</td> 4.161 + </tr> 4.162 + </thead> 4.163 + <tbody>" 4.164 + 4.165 + 4.166 +# main loop 4.167 +IFS=" 4.168 +" 4.169 +for PROJECT in $PROJ_LIST 4.170 +do 4.171 + IFS="|" 4.172 + echo "$PROJECT" | while read P_NAME PROJ_BASE P_SPAN PROJ_PODIR PROJ_DOCDIR PROJ_APPDIR 4.173 + do 4.174 + if [ -n "$P_SPAN" ]; then 4.175 + ROWSPAN=" rowspan=\"$P_SPAN\"" 4.176 + else 4.177 + ROWSPAN="" 4.178 + fi 4.179 + 4.180 + echof -n " <tr>" 4.181 + 4.182 + if [ -n "$P_NAME" ]; then 4.183 + echof "<td$ROWSPAN class=\"proj\"> 4.184 + <a href=\"http://hg.slitaz.org/$PROJ_BASE\">$P_NAME</a></td>" 4.185 + else 4.186 + echof "<!-- td -->" 4.187 + fi 4.188 + 4.189 + # unconditional out pot and po 4.190 + out_pot_po 4.191 + 4.192 + # out doc if exists 4.193 + if [ -n "$PROJ_DOCDIR" ]; then 4.194 + out_doc 4.195 + else 4.196 + echof " <td class=\"docs\"> </td>" 4.197 + fi 4.198 + 4.199 + # out apps if exists 4.200 + if [ -n "$PROJ_APPDIR" ]; then 4.201 + out_app 4.202 + elif [ -n "$P_NAME" ]; then 4.203 + echof " <td class=\"desk\"> </td>" 4.204 + fi 4.205 + 4.206 + 4.207 + echof " </tr>" 4.208 + 4.209 + IFS=" 4.210 +" 4.211 + done 4.212 +done 4.213 + 4.214 +echof " </tbody> 4.215 +</table> 4.216 +<p>Updated: $(date '+%x %X')</p>" 4.217 + 4.218 +mv "${INFO_FILE}.new" "$INFO_FILE" 4.219 +# the end