From 9b30b913a43905d032753c0438f8a5cbd5d1e9f3 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 28 Jan 2003 23:39:57 +0000 Subject: [PATCH] Rewrite postats.sh to: 1. Not need the existence of a Makefile in order to run; 2. Not result in php warnings about uninitialised variables if any of the translated, fuzzy or untranslated strings are missing. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5999 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/ChangeLog | 10 ++++ po/postats.sh | 158 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 134 insertions(+), 34 deletions(-) diff --git a/po/ChangeLog b/po/ChangeLog index 5e89b1b7e8..2bea1c6ce0 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,13 @@ +2003-01-28 Angus Leeming + + * es.po: msgfmt complained about a missing '\n'. + + * postats.sh: rewritten. Michael's original version resulted in + php warnings about uninitialised variables if any of the + translated, fuzzy or untranslated strings are missing (eg, because + there /are/ no untranslated strings). + Took the opportunity to make sure it does not need a Makefile to run. + 2003-01-28 Pauli Virtanen * fi.po: update diff --git a/po/postats.sh b/po/postats.sh index 3c47d229b2..f30084ca2e 100755 --- a/po/postats.sh +++ b/po/postats.sh @@ -15,9 +15,104 @@ # Invocation: # postats.sh po_files > "pathToWebPages"/i18n.php3 +error () { + while [ $# -ne 0 ] + do + echo $1 + shift + done + exit 1 +} -# *** The PHP header *** +# $1 is a string like +# '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.' +# $2 is the word following the number to be extracted, +# ie, 'translated', 'fuzzy', or 'untranslated'. +# Fills var $number with this number, or sets it to zero if the +# word is not found in the string. +extract_number () { + test $# -eq 2 || error 'extract_number expects 2 args' + number=0 + echo $1 | grep $2 >/dev/null || return + number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2.*/Z\1/" | cut -d 'Z' -f 2` +} + + +# Takes the name of the .po file and the .gmo file as input +# Regenerates the .gmo file and manipulates the output to stderr to +# fill var $output +run_msgfmt () { + test $# -eq 2 || error 'run_msgfmt expects 2 args' + + rm -f $gmofile + message=`$msgfmt --statistics -o $gmofile $1 2>&1 | grep "^[1-9]"` + #message=`make $gmofile 2>&1 | grep "^[1-9]"` + + extract_number "$message" translated + output='"msg_tr" => '$number + extract_number "$message" fuzzy + output=$output', "msg_fu" => '$number + extract_number "$message" untranslated + output=$output', "msg_nt" => '$number +} + + +# Passed the name of the .po file +dump_stats () { + test $# -eq 1 || error 'dump_stats expects 1 arg' + + file=$1 + test -f $file || { + echo "File $file does not exist" + return + } + + dir=`dirname $file` + pofile=`basename $file` + gmofile=`echo $pofile | sed 's/po$/gmo/'` + test $pofile != '' -a $pofile != $gmofile || { + echo "File $file is not a po file" + return + } + + ( + cd $dir + # $output is a string of the form + # '"msg_tr" => A, "msg_fu" => B, "msg_nt" => C' + # where A, B, C are extracted from the process of generating the .gmo + # file + run_msgfmt $pofile $gmofile + + # earching for a string of the form + # '"Last-Translator: Michael Schmitt \n"' + translator='"translator" => ""' + email='"email" => ""' + + input=`grep "Last-Translator" $pofile` && { + input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-` + + translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'` + translator='"translator" => "'$translator'"' + + email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1` + email='"email" => "'$email'"' + } + + # Searching for a string of the form + # '"PO-Revision-Date: 2003-01-18 03:00+0100\n"' + date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2` + date='"date" => "'$date'"' + + langcode=`echo $pofile | sed 's/\.po//'` + echo "array ( 'langcode' => '"$langcode"'," + echo ${output}, + echo ${translator}, ${email}, + echo "${date} )" + ) +} + +dump_head () { cat < + + '$y', " - touch $x - make 2>&1 $y.gmo | grep "^[1-9]" | - sed -e 's/\([0-9]*\) translated m[a-z]*[.,]/"msg_tr" => \1,/' | - sed -e 's/\([0-9]*\) fuzzy t[a-z]*[.,]/"msg_fu" => \1,/' | - sed -e 's/\([0-9]*\) untranslated m[a-z]*./"msg_nt" => \1,/' - # Format: "Last-Translator: Michael Schmitt \n" - grep "Last-Translator" $x | - sed -e 's/"Last-Translator: \(.*\)\( *\)<\(.*\)>\\n"/"translator" => "\1", "email" => "\3", /' - # Format: "PO-Revision-Date: 2003-01-18 03:00+0100\n" - grep "PO-Revision-Date" $x | - sed -e 's/"PO-Revision-Date: \(.*\) .*/"date" => "\1" )/' -done -echo ");" -echo "?>" - -# *** The PHP core part *** +dump_tail () { cat < -EOF - -cat < EOF +} + + +# The main body of the script +msgfmt=`type msgfmt | sed 's/msgfmt is *//'` +test msgfmt != '' || error "Unable to find 'msgfmt'" + +dump_head + +while [ $# -ne 0 ] +do + dump_stats $1 + shift + if [ $# -eq 0 ]; then + echo ');' + echo '?>' + else + echo ',' + fi +done + +dump_tail +