X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=po%2Fpostats.sh;h=7f1d9eda72fc9f2914c440337dd6a00fa1687597;hb=46ee486bdaf2a39538d9cabd2e7af722a4ede97d;hp=f30084ca2ea4d2b27e8d97246cf750afdfe23df7;hpb=9b30b913a43905d032753c0438f8a5cbd5d1e9f3;p=lyx.git diff --git a/po/postats.sh b/po/postats.sh index f30084ca2e..7f1d9eda72 100755 --- a/po/postats.sh +++ b/po/postats.sh @@ -15,103 +15,120 @@ # Invocation: # postats.sh po_files > "pathToWebPages"/i18n.php3 + +warning () { + echo $* 1>&2 +} + + error () { - while [ $# -ne 0 ] - do - echo $1 - shift - done + warning $* exit 1 } + # $1 is a string like # '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.' +# Any one of these substrings may not appear if the associated number is 0. +# # $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 +# +# extract_number 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` + # It /is/ safe to use 'Z' as a delimiter here. + number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2/Z\1Z/" | 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 -} +# $template is used by run_msgfmt, below, to fill $output. The function extracts +# the appropriate values from the data. +template="array ( 'langcode' => 'LC', +\"msg_tr\" => TR, \"msg_fu\" => FU, \"msg_nt\" => NT, +\"translator\" => \"AUTHOR\", \"email\" => \"EMAIL\", +\"date\" => \"DATE\" )" +readonly template -# Passed the name of the .po file -dump_stats () { - test $# -eq 1 || error 'dump_stats expects 1 arg' +# $1 is the name of the po file. +# +# The function runs msgfmt on it and fills var $output. +# All other variables created in the function are unset on exit. +run_msgfmt () { + test $# -eq 1 || error 'run_msgfmt expects 1 arg' - file=$1 - test -f $file || { - echo "File $file does not exist" + output= + test -f $1 || { + warning "File $1 does not exist" return } - dir=`dirname $file` - pofile=`basename $file` + origdir=`pwd` + dir=`dirname $1` + pofile=`basename $1` gmofile=`echo $pofile | sed 's/po$/gmo/'` test $pofile != '' -a $pofile != $gmofile || { - echo "File $file is not a po file" + warning "File $1 is not a po file" + unset origdir dir pofile gmofile 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 + unset dir - # earching for a string of the form - # '"Last-Translator: Michael Schmitt \n"' - translator='"translator" => ""' - email='"email" => ""' + langcode=`echo $pofile | sed 's/\.po$//'` + # 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` + + # Searching for a string of the form + # '"Last-Translator: Michael Schmitt \n"' + translator= + 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} )" - ) + unset input + + # Run msgfmt on the pofile, filling $message with the raw info. + message=`$msgfmt --statistics -o $gmofile $pofile 2>&1 | grep "^[1-9]"` || { + warning "Unable to run msgfmt successfully on file $1" + cg $origdir + unset origdir pofile gmofile + return + } + unset pofile gmofile + + extract_number "$message" 'translated' + translated=$number + + extract_number "$message" 'fuzzy' + fuzzy=$number + + extract_number "$message" 'untranslated' + untranslated=$number + unset message number + + output=`echo "$template" | sed "s/LC/$langcode/; \ + s/TR/$translated/; s/FU/$fuzzy/; s/NT/$untranslated/; \ + s/AUTHOR/$translator/; s/EMAIL/$email/; s/DATE/$date/"` + + unset langcode date translator email untranslated fuzzy translated + cd $origdir + unset origdir } + +# The head of the generated php file. dump_head () { cat < 'Bulgarian', - 'ca' => 'Catalan', - 'cs' => 'Czech', - 'da' => 'Danish', - 'de' => 'German', - 'es' => 'Spanish', - 'eu' => 'Basque', - 'fi' => 'Finnish', - 'fr' => 'French', - 'he' => 'Hebrew', - 'hu' => 'Hungarian', - 'it' => 'Italian', - 'nl' => 'Dutch', - 'no' => 'Norwegian', - 'pl' => 'Polish', - 'pt' => 'Portuguese', - 'ro' => 'Romanian', - 'ru' => 'Russian', - 'sk' => 'Slovak', - 'sl' => 'Slovenian', - 'sv' => 'Swedish', - 'tr' => 'Turkish', - 'wa' => 'Wallon' - ); - - \$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt']; - - function cmp (\$a, \$b) { - if (\$a['msg_tr'] == \$b['msg_tr']) { - return 0; - } - return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1; - } - - usort (\$podata, "cmp"); - ?> - -

- The following table lists all translations available with the number of messages - given for the LyX main development branch (currently 1.3.0cvs). - Unfortunately, only a few languages are well-supported. - For every release, the LyX development team may decide to exclude some of the - translations from the distribution in order not to confuse the user by a strongly - mixed-language interface. -

-

- Explanation: -

-
    -
  • Translated: The number of translated messages
  • -
  • Fuzzy: The number of fuzzy messages; these are not considered - for LyX output but solely serve as a hint for the translators
  • -
  • Untranslated: The number of untranslated messages; the - default language (i.e., English) will be used in the LyX outputs
  • -
- - - - - - - - - - - - - "; - - if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) { - \$style="style='background:#009900'"; - } else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) { - \$style="style='background:#AAAA00'"; - } else { - \$style="style='background:#AA3333'"; - } - - print ""; - - print ""; - - print ""; - - print ""; - - print ""; - - print ""; - - print "\n"; - } - ?> - -
LanguageTranslatedFuzzyUntranslatedRevision DateTranslator
" . \$lang[\$info['langcode']] . "" . \$info['msg_tr'] . ""; - if (isset(\$info['msg_fu'])) { - print \$info['msg_fu']; - } else { - print "0"; - } - print ""; - if (isset(\$info['msg_nt'])) { - print \$info['msg_nt']; - } else { - print "0"; - } - print "" . \$info['date'] . ""; - if (\$info['email'] == "") { - print \$info['translator']; - } else { - print "" . - \$info['translator'] . ""; - } - print "
- + 'Bulgarian', + 'ca' => 'Catalan', + 'cs' => 'Czech', + 'da' => 'Danish', + 'de' => 'German', + 'es' => 'Spanish', + 'eu' => 'Basque', + 'fi' => 'Finnish', + 'fr' => 'French', + 'he' => 'Hebrew', + 'hu' => 'Hungarian', + 'it' => 'Italian', + 'nl' => 'Dutch', + 'no' => 'Norwegian', + 'pl' => 'Polish', + 'pt' => 'Portuguese', + 'ro' => 'Romanian', + 'ru' => 'Russian', + 'sk' => 'Slovak', + 'sl' => 'Slovenian', + 'sv' => 'Swedish', + 'tr' => 'Turkish', + 'wa' => 'Walloon' +); + +\$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt']; + +function cmp (\$a, \$b) { + if (\$a['msg_tr'] == \$b['msg_tr']) { + return 0; + } + return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1; +} + +usort (\$podata, "cmp"); +?> + +

+ The following table details the current state of the translations of the + LyX GUI for the main LyX development branch (currently 1.3.0cvs). + Unfortunately, only a few languages are well-supported. The LyX term may, + therefore, decide to exclude some of the translations from a formal + release in order not to confuse the user with a strongly mixed-language + interface. +

+

+ Explanation: +

+
    +
  • Translated: The number of translated messages
  • +
  • Fuzzy: The number of fuzzy messages; these are not considered + for LyX output but solely serve as a hint for the translators
  • +
  • Untranslated: The number of untranslated messages; the + default language (i.e., English) will be used in the LyX outputs
  • +
+ + + + + + + + + + + + +"; + + if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) { + \$style="style='background:#009900'"; + } else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) { + \$style="style='background:#AAAA00'"; + } else { + \$style="style='background:#AA3333'"; + } + + print ""; + + print ""; + + print ""; + + print ""; + + print ""; + + print ""; + + print "\n"; +} +?> + +
LanguageTranslatedFuzzyUntranslatedRevision DateTranslator
" . \$lang[\$info['langcode']] . "" . \$info['msg_tr'] . ""; + if (isset(\$info['msg_fu'])) { + print \$info['msg_fu']; + } else { + print "0"; + } + print ""; + if (isset(\$info['msg_nt'])) { + print \$info['msg_nt']; + } else { + print "0"; + } + print "" . \$info['date'] . ""; + if (\$info['email'] == "") { + print \$info['translator']; + } else { + print "" . + \$info['translator'] . ""; + } + print "
+ EOF } # The main body of the script -msgfmt=`type msgfmt | sed 's/msgfmt is *//'` -test msgfmt != '' || error "Unable to find 'msgfmt'" +msgfmt=`which msgfmt` +test $msgfmt != '' || error "Unable to find 'msgfmt'. Cannot proceed." dump_head while [ $# -ne 0 ] do - dump_stats $1 + run_msgfmt $1 shift if [ $# -eq 0 ]; then - echo ');' - echo '?>' + echo "${output});" + echo '?>' else - echo ',' + echo "${output}," + echo fi done dump_tail - +# The end