5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # author: Michael Schmitt, michael.schmitt@teststep.org
10 # This script extracts some information from the po file headers (last
11 # translator, revision date), generates the corresponding gmo files
12 # to retrieve the number of translated/fuzzy/untranslated messages,
13 # and generates a PHP web page.
16 # postats.sh po_files > "pathToWebPages"/i18n.php3
28 # '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.'
29 # $2 is the word following the number to be extracted,
30 # ie, 'translated', 'fuzzy', or 'untranslated'.
31 # Fills var $number with this number, or sets it to zero if the
32 # word is not found in the string.
34 test $# -eq 2 || error 'extract_number expects 2 args'
37 echo $1 | grep $2 >/dev/null || return
38 # It /is/ safe to use 'Z' as a delimiter here.
39 number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2.*/Z\1/" | cut -d 'Z' -f 2`
43 # Takes the name of the .po file and the .gmo file as input
44 # Regenerates the .gmo file and manipulates the output to stderr to
47 test $# -eq 2 || error 'run_msgfmt expects 2 args'
50 message=`$msgfmt --statistics -o $2 $1 2>&1 | grep "^[1-9]"`
51 #message=`make $2 2>&1 | grep "^[1-9]"`
53 extract_number "$message" translated
54 output='"msg_tr" => '$number
55 extract_number "$message" fuzzy
56 output=$output', "msg_fu" => '$number
57 extract_number "$message" untranslated
58 output=$output', "msg_nt" => '$number
62 # Passed the name of the .po file
64 test $# -eq 1 || error 'dump_stats expects 1 arg'
68 echo "File $file does not exist"
73 pofile=`basename $file`
74 gmofile=`echo $pofile | sed 's/po$/gmo/'`
75 test $pofile != '' -a $pofile != $gmofile || {
76 echo "File $file is not a po file"
82 # $output is a string of the form
83 # '"msg_tr" => A, "msg_fu" => B, "msg_nt" => C'
84 # where A, B, C are extracted from the process of generating the .gmo
86 run_msgfmt $pofile $gmofile
88 # earching for a string of the form
89 # '"Last-Translator: Michael Schmitt <Michael.Schmitt@teststep.org>\n"'
90 translator='"translator" => ""'
93 input=`grep "Last-Translator" $pofile` && {
94 input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-`
96 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
97 translator='"translator" => "'$translator'"'
99 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
100 email='"email" => "'$email'"'
103 # Searching for a string of the form
104 # '"PO-Revision-Date: 2003-01-18 03:00+0100\n"'
105 date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2`
106 date='"date" => "'$date'"'
108 langcode=`echo $pofile | sed 's/\.po//'`
109 echo "array ( 'langcode' => '"$langcode"',"
111 echo ${translator}, ${email},
119 // What's the title of the page?
120 \$title = "LyX i18n";
121 // What's the short name of the page in the navigation bar?
123 // Who is the author?
124 \$author="Michael Schmitt";
125 // Full name of the file (relative path from LyX home page -- i.e., it should
126 // be "foo.php3" or "bar/foo.php3")
127 \$file_full="i18n.php3";
129 include("start.php3");
131 error_reporting(E_ALL);
159 'pt' => 'Portuguese',
169 \$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt'];
171 function cmp (\$a, \$b) {
172 if (\$a['msg_tr'] == \$b['msg_tr']) {
175 return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1;
178 usort (\$podata, "cmp");
182 The following table lists all translations available with the number of messages
183 given for the LyX main development branch (currently 1.3.0cvs).
184 Unfortunately, only a few languages are well-supported.
185 For every release, the LyX development team may decide to exclude some of the
186 translations from the distribution in order not to confuse the user by a strongly
187 mixed-language interface.
193 <li><i>Translated:</i> The number of translated messages</li>
194 <li><i>Fuzzy:</i> The number of fuzzy messages; these are not considered
195 for LyX output but solely serve as a hint for the translators</li>
196 <li><i>Untranslated:</i> The number of untranslated messages; the
197 default language (i.e., English) will be used in the LyX outputs</li>
199 <table class="center" frame="box" rules="all" border="2" cellpadding="5">
205 <td>Untranslated</td>
206 <td>Revision Date</td>
212 while (list(\$foo,\$info) = each(\$podata)) {
215 if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) {
216 \$style="style='background:#009900'";
217 } else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) {
218 \$style="style='background:#AAAA00'";
220 \$style="style='background:#AA3333'";
223 print "<td \$style>" . \$lang[\$info['langcode']] . "</td>";
225 print "<td \$style align=\"right\">" . \$info['msg_tr'] . "</td>";
227 print "<td \$style align=\"right\">";
228 if (isset(\$info['msg_fu'])) {
229 print \$info['msg_fu'];
235 print "<td \$style align=\"right\">";
236 if (isset(\$info['msg_nt'])) {
237 print \$info['msg_nt'];
243 print "<td \$style align=\"center\">" . \$info['date'] . "</td>";
245 print "<td \$style>";
246 if (\$info['email'] == "") {
247 print \$info['translator'];
249 print "<a href=\"mailto:" . \$info['email'] . "\">" .
250 \$info['translator'] . "</a>";
266 # The main body of the script
267 msgfmt=`type msgfmt | sed 's/msgfmt is *//'`
268 test msgfmt != '' || error "Unable to find 'msgfmt'"
276 if [ $# -eq 0 ]; then