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 number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2.*/Z\1/" | cut -d 'Z' -f 2`
42 # Takes the name of the .po file and the .gmo file as input
43 # Regenerates the .gmo file and manipulates the output to stderr to
46 test $# -eq 2 || error 'run_msgfmt expects 2 args'
49 message=`$msgfmt --statistics -o $gmofile $1 2>&1 | grep "^[1-9]"`
50 #message=`make $gmofile 2>&1 | grep "^[1-9]"`
52 extract_number "$message" translated
53 output='"msg_tr" => '$number
54 extract_number "$message" fuzzy
55 output=$output', "msg_fu" => '$number
56 extract_number "$message" untranslated
57 output=$output', "msg_nt" => '$number
61 # Passed the name of the .po file
63 test $# -eq 1 || error 'dump_stats expects 1 arg'
67 echo "File $file does not exist"
72 pofile=`basename $file`
73 gmofile=`echo $pofile | sed 's/po$/gmo/'`
74 test $pofile != '' -a $pofile != $gmofile || {
75 echo "File $file is not a po file"
81 # $output is a string of the form
82 # '"msg_tr" => A, "msg_fu" => B, "msg_nt" => C'
83 # where A, B, C are extracted from the process of generating the .gmo
85 run_msgfmt $pofile $gmofile
87 # earching for a string of the form
88 # '"Last-Translator: Michael Schmitt <Michael.Schmitt@teststep.org>\n"'
89 translator='"translator" => ""'
92 input=`grep "Last-Translator" $pofile` && {
93 input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-`
95 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
96 translator='"translator" => "'$translator'"'
98 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
99 email='"email" => "'$email'"'
102 # Searching for a string of the form
103 # '"PO-Revision-Date: 2003-01-18 03:00+0100\n"'
104 date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2`
105 date='"date" => "'$date'"'
107 langcode=`echo $pofile | sed 's/\.po//'`
108 echo "array ( 'langcode' => '"$langcode"',"
110 echo ${translator}, ${email},
118 // What's the title of the page?
119 \$title = "LyX i18n";
120 // What's the short name of the page in the navigation bar?
122 // Who is the author?
123 \$author="Michael Schmitt";
124 // Full name of the file (relative path from LyX home page -- i.e., it should
125 // be "foo.php3" or "bar/foo.php3")
126 \$file_full="i18n.php3";
128 include("start.php3");
130 error_reporting(E_ALL);
158 'pt' => 'Portuguese',
168 \$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt'];
170 function cmp (\$a, \$b) {
171 if (\$a['msg_tr'] == \$b['msg_tr']) {
174 return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1;
177 usort (\$podata, "cmp");
181 The following table lists all translations available with the number of messages
182 given for the LyX main development branch (currently 1.3.0cvs).
183 Unfortunately, only a few languages are well-supported.
184 For every release, the LyX development team may decide to exclude some of the
185 translations from the distribution in order not to confuse the user by a strongly
186 mixed-language interface.
192 <li><i>Translated:</i> The number of translated messages</li>
193 <li><i>Fuzzy:</i> The number of fuzzy messages; these are not considered
194 for LyX output but solely serve as a hint for the translators</li>
195 <li><i>Untranslated:</i> The number of untranslated messages; the
196 default language (i.e., English) will be used in the LyX outputs</li>
198 <table class="center" frame="box" rules="all" border="2" cellpadding="5">
204 <td>Untranslated</td>
205 <td>Revision Date</td>
211 while (list(\$foo,\$info) = each(\$podata)) {
214 if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) {
215 \$style="style='background:#009900'";
216 } else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) {
217 \$style="style='background:#AAAA00'";
219 \$style="style='background:#AA3333'";
222 print "<td \$style>" . \$lang[\$info['langcode']] . "</td>";
224 print "<td \$style align=\"right\">" . \$info['msg_tr'] . "</td>";
226 print "<td \$style align=\"right\">";
227 if (isset(\$info['msg_fu'])) {
228 print \$info['msg_fu'];
234 print "<td \$style align=\"right\">";
235 if (isset(\$info['msg_nt'])) {
236 print \$info['msg_nt'];
242 print "<td \$style align=\"center\">" . \$info['date'] . "</td>";
244 print "<td \$style>";
245 if (\$info['email'] == "") {
246 print \$info['translator'];
248 print "<a href=\"mailto:" . \$info['email'] . "\">" .
249 \$info['translator'] . "</a>";
265 # The main body of the script
266 msgfmt=`type msgfmt | sed 's/msgfmt is *//'`
267 test msgfmt != '' || error "Unable to find 'msgfmt'"
275 if [ $# -eq 0 ]; then