website diff lib/i18n-info.sh @ 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
children 359e00fe4d11
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/i18n-info.sh	Fri Jul 27 13:59:05 2012 +0000
     1.3 @@ -0,0 +1,216 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +# for english po statistics using `msgfmt --statistics`
     1.7 +LC_ALL=C; export LC_ALL
     1.8 +
     1.9 +HG_URL="http://hg.slitaz.org"
    1.10 +INFO_FILE="/var/cache/slitaz/website/i18n.html"
    1.11 +mkdir -p "/var/cache/slitaz/website"
    1.12 +touch "${INFO_FILE}.new"
    1.13 +echo "" > "${INFO_FILE}.new"
    1.14 +
    1.15 +# echo to file
    1.16 +echof()
    1.17 +{
    1.18 +	echo "$@" >> "${INFO_FILE}.new"
    1.19 +}
    1.20 +
    1.21 +# print table cells with 'pot' and 'po's
    1.22 +out_pot_po()
    1.23 +{
    1.24 +	TMP_PO="/tmp/i18n.po"
    1.25 +	# get all links to files in folder
    1.26 +	LINKS=$(wget "$HG_URL/$PROJ_BASE/$PROJ_PODIR/" -q -O - | \
    1.27 +		grep -A 1 "filename" | \
    1.28 +		grep "href" | \
    1.29 +		sed 's|.*"\([^"]*\)".*|http://hg.slitaz.org\1|g' | \
    1.30 +		sed 's|/file/[^/]*/|/raw-file/tip/|g')
    1.31 +	# get link to 'pot' and print cell
    1.32 +	LINK_POT=$(echo "$LINKS" | grep -e '\.pot$')
    1.33 +
    1.34 +	echof "
    1.35 +			<td class=\"pot\">
    1.36 +				<a href=\"$LINK_POT\">
    1.37 +				$(echo $LINK_POT | sed 's|.*/\([^/]*\.pot\)$|\1|')</a></td>
    1.38 +			<td class=\"po\">"
    1.39 +
    1.40 +	# process 'po's
    1.41 +	IFS="
    1.42 +"
    1.43 +	for FILE in $(echo "$LINKS" | grep -e '.po$'); do
    1.44 +		# temp download
    1.45 +		wget $FILE -q -O $TMP_PO
    1.46 +		# get stats
    1.47 +		STAT=$(msgfmt --statistics $TMP_PO 2>&1 | sed 's|[^0-9 ]||g')
    1.48 +		rm $TMP_PO
    1.49 +		# language; number of translated and untranslated entries
    1.50 +		LNG=$(echo $FILE | sed 's|.*/\([^/]*\)\.po$|\1|')
    1.51 +		TRAN=$(echo $STAT | cut -d" " -f1)
    1.52 +		UNTR=$(($(echo $STAT | awk '{print $2}') + 0))
    1.53 +		# percents done
    1.54 +		PCNT=$(($TRAN * 100 / ($TRAN + $UNTR)))
    1.55 +		echof "				<a href=\"$FILE\">$LNG<hr/>${PCNT}%</a>"
    1.56 +	done
    1.57 +	echof "			</td>"
    1.58 +}
    1.59 +
    1.60 +
    1.61 +# print table cell with html documentations
    1.62 +out_doc()
    1.63 +{
    1.64 +	# get all links to files in folder
    1.65 +	LINKS=$(wget "$HG_URL/$PROJ_BASE/$PROJ_DOCDIR/" -q -O - | \
    1.66 +		grep -A 1 "filename" | \
    1.67 +		grep "href" | \
    1.68 +		sed 's|.*"\([^"]*\)".*|http://hg.slitaz.org\1|g' | \
    1.69 +		sed 's|/file/[^/]*/|/raw-file/tip/|g')
    1.70 +
    1.71 +	echof "			<td class=\"docs\">"
    1.72 +
    1.73 +	IFS="
    1.74 +"
    1.75 +	# get name of subproject, example: subproject 'tazusb-box' from 'tazusb'
    1.76 +	SUB_PROJ=$(echo "$PROJ_PODIR" | sed 's|.*/\(.*\)|\1|')
    1.77 +	for DOCUMENT in $(echo "$LINKS" | grep -e '.html$'); do
    1.78 +		# strip project and subproject names from doc filename
    1.79 +		NAME_DOC=$(echo $DOCUMENT | \
    1.80 +			sed 's|.*/\([^/]*\)\.html$|\1|' | \
    1.81 +			sed 's|'$PROJ_BASE'\.||; s|'$SUB_PROJ'\.||')
    1.82 +		# first part of filename, example faq.en -> faq
    1.83 +		NAME_DOC1=$(echo $NAME_DOC | cut -d"." -f1)
    1.84 +		# second part of filename, faq.en -> en
    1.85 +		NAME_DOC2=$(echo $NAME_DOC | cut -d"." -f2)
    1.86 +		# if filename have only [lang] then rename it to doc.[lang]
    1.87 +		if [ "x$NAME_DOC2" == "x" ]; then
    1.88 +			NAME_DOC2=$NAME_DOC1
    1.89 +			NAME_DOC1="doc"
    1.90 +		fi
    1.91 +		# not print 'linked' common documents, only localized ones
    1.92 +		# (often link [project].html pointed to [project].en.html)
    1.93 +		if [ "$NAME_DOC" != "$SUB_PROJ" ] && [ "$NAME_DOC" != "$PROJ_BASE" ]; then
    1.94 +			echof "				<a href=\"$DOCUMENT\">$NAME_DOC1<br/>$NAME_DOC2</a>"
    1.95 +		fi
    1.96 +	done
    1.97 +	echof "			</td>"
    1.98 +}
    1.99 +
   1.100 +
   1.101 +# print table cell with link to .desktop files
   1.102 +out_app()
   1.103 +{
   1.104 +	APP_DIR="$HG_URL/$PROJ_BASE/file/tip/$PROJ_APPDIR"
   1.105 +	PAGE=$(wget $APP_DIR -q -O -)
   1.106 +	LINKS=$(echo "$PAGE" | grep -A 1 "filename" | grep "href" | wc -l)
   1.107 +	# plural form
   1.108 +	if [ "$LINKS" == "1" ]; then
   1.109 +		APP_TEXT="1<br/>item"
   1.110 +	else
   1.111 +		APP_TEXT="$LINKS<br/>items"
   1.112 +	fi
   1.113 +
   1.114 +	# rowspan: folder with desktop files is one for project
   1.115 +	# combine all subprojects
   1.116 +	echof "			<td class=\"desk\"$ROWSPAN><a href=\"$APP_DIR\">$APP_TEXT</a></td>"
   1.117 +}
   1.118 +
   1.119 +
   1.120 +
   1.121 +# standard path to folder with 'pot' and 'po's
   1.122 +S="file/tip/po"
   1.123 +# standard path to doc folder
   1.124 +D="file/tip/doc"
   1.125 +
   1.126 +# list of all processed projects; fields description:
   1.127 +# [1]: Human readable project name (once)
   1.128 +# [2]: Project base:  http://hg.slitaz.org/[2]
   1.129 +# [3]: Spanned cells (number or empty)
   1.130 +# [4]: Pot&po folder: http://hg.slitaz.org/[2]/[4]/
   1.131 +# [5]: Docs folder:   http://hg.slitaz.org/[2]/[5]/
   1.132 +# [6]: Apps folder:   http://hg.slitaz.org/[2]/file/tip/[6]/
   1.133 +PROJ_LIST="
   1.134 +SliTaz Base Files|slitaz-base-files||$S||rootfs/usr/share/applications
   1.135 +pkgs.slitaz.org|slitaz-forge/file/tip/pkgs||po||
   1.136 +SliTaz Pizza|slitaz-pizza||$S|$D|
   1.137 +SliTaz Tools|slitaz-tools|5|$S/slitaz-boxes||applications
   1.138 +|slitaz-tools||$S/slitaz-tools||
   1.139 +|slitaz-tools||$S/tazbox||
   1.140 +|slitaz-tools||$S/tazdrop||
   1.141 +|slitaz-tools||$S/tazinst|$D|
   1.142 +SSFS|ssfs|2|$S/server||data
   1.143 +|ssfs||$S/ssfs||
   1.144 +TazBug|tazbug||$S||data
   1.145 +TazLito|tazlito||$S/tazlito-wiz|$D|applications
   1.146 +TazPanel|tazpanel||$S|$D|data
   1.147 +TazPkg|tazpkg|2|$S/tazpkg|$D|applications
   1.148 +|tazpkg||$S/tazpkg-notify||
   1.149 +TazUsb|tazusb|2|$S/tazusb|$D|applications
   1.150 +|tazusb||$S/tazusb-box||"
   1.151 +
   1.152 +# print table header
   1.153 +echof "
   1.154 +<table>
   1.155 +	<thead class=\"thead\">
   1.156 +		<tr><td>Project</td>
   1.157 +			<td>POT file</td>
   1.158 +			<td>PO files</td>
   1.159 +			<td>Docs</td>
   1.160 +			<td>Menu</td>
   1.161 +		</tr>
   1.162 +	</thead>
   1.163 +	<tbody>"
   1.164 +
   1.165 +
   1.166 +# main loop
   1.167 +IFS="
   1.168 +"
   1.169 +for PROJECT in $PROJ_LIST
   1.170 +do
   1.171 +	IFS="|"
   1.172 +	echo "$PROJECT" | while read P_NAME PROJ_BASE P_SPAN PROJ_PODIR PROJ_DOCDIR PROJ_APPDIR
   1.173 +	do
   1.174 +		if [ -n "$P_SPAN" ]; then
   1.175 +			ROWSPAN=" rowspan=\"$P_SPAN\""
   1.176 +		else
   1.177 +			ROWSPAN=""
   1.178 +		fi
   1.179 +
   1.180 +		echof -n "		<tr>"
   1.181 +
   1.182 +		if [ -n "$P_NAME" ]; then
   1.183 +			echof "<td$ROWSPAN class=\"proj\">
   1.184 +				<a href=\"http://hg.slitaz.org/$PROJ_BASE\">$P_NAME</a></td>"
   1.185 +		else
   1.186 +			echof "<!-- td -->"
   1.187 +		fi
   1.188 +
   1.189 +		# unconditional out pot and po
   1.190 +		out_pot_po
   1.191 +
   1.192 +		# out doc if exists
   1.193 +		if [ -n "$PROJ_DOCDIR" ]; then
   1.194 +			out_doc
   1.195 +		else
   1.196 +			echof "			<td class=\"docs\">&nbsp;</td>"
   1.197 +		fi
   1.198 +
   1.199 +		# out apps if exists
   1.200 +		if [ -n "$PROJ_APPDIR" ]; then
   1.201 +			out_app
   1.202 +		elif [ -n "$P_NAME" ]; then
   1.203 +			echof "			<td class=\"desk\">&nbsp;</td>"
   1.204 +		fi
   1.205 +
   1.206 +
   1.207 +		echof "		</tr>"
   1.208 +
   1.209 +		IFS="
   1.210 +"
   1.211 +	done
   1.212 +done
   1.213 +
   1.214 +echof "	</tbody>
   1.215 +</table>
   1.216 +<p>Updated: $(date '+%x %X')</p>"
   1.217 +
   1.218 +mv "${INFO_FILE}.new" "$INFO_FILE"
   1.219 +# the end