#!/bin/bash # Check translations, generate verbose statistics. # Copyright (C) 2004 Recai Oktas # Copyright (C) 2007-2008 Andrius Štikonas (my code can also be used under GPLv3 or any later) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as published by # the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . source variables LC_NUMERIC="en_US.UTF-8" ODD_CHARS='�' CL=0 # counter for css style STATUS="OK" # Total status of translations if [ ! $MSGFMT ]; then echo -e "\E[31mThis program needs the msgfmt utility."; tput sgr0 exit 1 fi if [ ! $ISUTF8 ]; then echo -e "\E[31mThis program needs the isutf8 utility."; tput sgr0 exit 1 fi for BRANCH in $TRUNK $BRANCHES; do echo -e "Repository: \E[34m$BRANCH"; tput sgr0 DIR="$PREFIX-$BRANCH" STATSFILE="statistics-$BRANCH.xhtml" ERRORS="translation-errors-$BRANCH" nerror=0; nwarn=0; npo=0; nt=0; nu=0; nf=0 rm -f $STATSFILE echo "> $STATSFILE echo "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo " " >> $STATSFILE echo " " >> $STATSFILE echo " " >> $STATSFILE echo " " >> $STATSFILE echo " Battle for Wesnoth" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "
" >> $STATSFILE echo "
" >> $STATSFILE echo "
" >> $STATSFILE echo " \"Wesnoth" >> $STATSFILE echo "
" >> $STATSFILE echo "
" >> $STATSFILE echo "" >> $STATSFILE echo "
" >> $STATSFILE echo "
    " >> $STATSFILE echo "
  • Home
  • " >> $STATSFILE echo "
  • Play
  • " >> $STATSFILE echo "" >> $STATSFILE echo "
  • Create
  • " >> $STATSFILE echo "
  • Forums
  • " >> $STATSFILE echo "
  • Support
  • " >> $STATSFILE echo "
  • Project
  • " >> $STATSFILE echo "
  • Credits
  • " >> $STATSFILE echo "
" >> $STATSFILE echo "
" >> $STATSFILE echo "" >> $STATSFILE echo "

Wesnoth translation stats

" >> $STATSFILE echo "

Last update: " >> $STATSFILE LC_TIME="en_US.UTF-8" date >> $STATSFILE echo "

" >> $STATSFILE echo "

" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "
" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE for dir in `ls $BRANCH/wesnoth* -d`; do file=$DIR"/"`basename $dir`"."$LCODE".po"; if [ ! -f $file ]; then file=$BRANCH"/"`basename $dir`"/"$LCODE".po" filename=$BRANCH`basename $dir`"/"$dir"."$LCODE else filename=`echo $file | sed s/.po//` fi npo=$(($npo + 1)); has_errors="no"; has_warnings="no"; # Extract the declared charset, may be we use this in future. charset=`sed -n '/^"Content-Type:/ s/.*charset=\([a-zA-Z0-9_-]*\).*/\1/p' $file` echo -n "Checking $file for UTF-8 inconsistencies... " if $ISUTF8 <$file >/dev/null 2>&1; then if ! echo $charset | grep -qi "UTF-8"; then has_errors="yes" echo -e "\E[31mFAILED; non UTF-8 charset declaration for UTF-8 content"; tput sgr0 echo "$file: non UTF-8 charset declared for UTF-8 content; expect to see 'charset=UTF-8'." >> $ERRORS else echo -e "\E[32mOK"; tput sgr0 fi else if echo $charset | grep -qi "UTF-8"; then has_errors="yes" echo -e "\E[31mFAILED; non UTF-8 content for UTF-8 charset declaration"; tput sgr0 echo "$file: UTF-8 charset declared for non UTF-8 content; expect to see a non UTF-8 charset." >> $ERRORS else echo -e "\E[32mOK"; tput sgr0 fi fi echo -n "Checking $file for odd characters... " if grep -nH $ODD_CHARS $file >> $ERRORS; then has_warnings="yes" echo -e "\E[31mFAILED; odd characters found"; tput sgr0 echo "$file: one or more odd character from the '$ODD_CHARS' set found." >> $ERRORS else echo -e "\E[32mOK"; tput sgr0 fi # Makes sense only if the file passed the UTF-8 check. if [ "$has_errors" = "no" ]; then echo -n "Checking $file with msgfmt... " if ! LC_MESSAGES=C $MSGFMT --check -o /dev/null $file >> $ERRORS; then has_errors="yes" echo -e "\E[31mFAILED"; tput sgr0 else echo -e "\E[32mOK"; tput sgr0 fi fi r=0; rf=0; ru=0; t=0; u=0; f=0; rt=0 if [ "$has_errors" = "yes" ]; then nerror=$(($nerror + 1)) sum=0 st="Error" if [ $STATUS = "OK" ]; then STATUS="Error" fi if [ $STATUS = "Warning" ]; then STATUS="Error" fi else stat=`LC_MESSAGES=C $MSGFMT --statistics -o /dev/null $file 2>&1` t=`echo "$stat" | sed -ne 's/\([0-9]\+\) translated .*/\1/p'`; t=${t:-0} u=`echo "$stat" | sed -ne 's/.* \([0-9]\+\) untranslated .*/\1/p'`; u=${u:-0} f=`echo "$stat" | sed -ne 's/.* \([0-9]\+\) fuzzy translation.*/\1/p'`; f=${f:-0} sum=$(($t + $f + $u)) if [ ! "$sum" -eq 0 ]; then rt=`printf '%s%d%s%d\n' "scale=2; 100*" $t "/" $sum | bc` fi if [ ! "$sum" -eq 0 ]; then rf=`printf '%s%d%s%d\n' "scale=2; 100*" $f "/" $sum | bc` fi if [ ! "$sum" -eq 0 ]; then ru=`printf '%s%d%s%d\n' "scale=2; 100*" $u "/" $sum | bc` fi nt=$(($nt + $t)); nu=$(($nu + $u)); nf=$(($nf + $f)) st="OK" if [ "$has_warnings" = "yes" ]; then nwarn=$(($nwarn + 1)) st='Warning' if [ "$STATUS" = "OK" ]; then STATUS='Warning' fi fi fi echo "" >> $STATSFILE CL=$(( ($CL+1)%2 )) echo " " >> $STATSFILE echo " " >> $STATSFILE echo " " >> $STATSFILE printf '%s%d%s%.2f%s\n' " " >> $STATSFILE echo " " >> $STATSFILE printf '%s%d%s%.2f%s\n' " " >> $STATSFILE echo " " >> $STATSFILE printf '%s%d%s%.2f%s\n' " " >> $STATSFILE echo " " >> $STATSFILE n4=`printf '%s%f\n' "scale=2; 3*" $rt | bc` n6=`printf '%s%f\n' "scale=2; 3*" $rf | bc` n8=`printf '%s%f\n' "scale=2; 3*" $ru | bc` printf '%s%.2f%s%.2f%s%.2f%s\n' " " >> $STATSFILE echo "" >> $STATSFILE done if [ "$npo" -eq 0 ]; then echo -e "\E[31mNo '${PO}.po' file under '$DIR'."; tput sgr0 exit 0 fi if [ "$nerror" -gt 0 ]; then echo -n -e "\E[31mFatal errors found. See '" tput smso; echo -n "$ERRORS"; tput rmso echo -e "' for details."; tput sgr0 else echo -e "\E[32mNo fatal errors found."; tput sgr0 if [ -s "$ERRORS" ]; then echo -n -e "\E[31m See '" tput smso; echo -n "$ERRORS"; tput rmso echo -e "' for warnings."; tput sgr0 else rm -f $ERRORS fi fi if [ "$npo" = "$nerror" ]; then echo -e "\E[31mAll files have fatal errors."; tput sgr0 else sum=$((${nt} + ${nf} + ${nu})) nrt=`printf '%s%d%s%d\n' "scale=2; 100*" $nt "/" $sum | bc` nrf=`printf '%s%d%s%d\n' "scale=2; 100*" $nf "/" $sum | bc` nru=`printf '%s%d%s%d\n' "scale=2; 100*" $nu "/" $sum | bc` echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE printf '%s%.2f%s\n' "" >> $STATSFILE echo "" >> $STATSFILE printf '%s%.2f%s\n' "" >> $STATSFILE echo "" >> $STATSFILE printf '%s%.2f%s\n' "" >> $STATSFILE echo "" >> $STATSFILE nrt=`printf '%s%f\n' "scale=2; 3*" $nrt | bc` nrf=`printf '%s%f\n' "scale=2; 3*" $nrf | bc` nru=`printf '%s%f\n' "scale=2; 3*" $nru | bc` printf '%s%.2f%s%.2f%s%.2f%s\n' "" >> $STATSFILE echo "" >> $STATSFILE echo "
FileStatustranslated%fuzzy%untranslated%totalgraph
`basename $filename`$st$t" $rt "$f" $rf "$u" $ru "$sum\"translated\"/\"fuzzy\"/\"untranslated\"/
Total$STATUS$nt" $nrt "$nf" $nrf "$nu" $nru "$((${nt} + ${nf} + ${nu}))\"translated\"/\"fuzzy\"/\"untranslated\"/
" >> $STATSFILE echo "
" >> $STATSFILE echo "

" >> $STATSFILE echo "
" >> $STATSFILE echo "" >> $STATSFILE echo "
" >> $STATSFILE echo "© 2003-"`date +%Y`" The Battle for Wesnoth
" >> $STATSFILE echo "
" >> $STATSFILE echo "> $STATSFILE echo "alt=\"Valid XHTML 1.1!\" height=\"31\" width=\"88\" />" >> $STATSFILE echo "
" >> $STATSFILE echo "
" >> $STATSFILE echo "
" >> $STATSFILE echo "" >> $STATSFILE echo "" >> $STATSFILE fi done # Exit with error count just because it may sense. exit $nerror