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
31 # '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.'
32 # Any one of these substrings may not appear if the associated number is 0.
34 # $2 is the word following the number to be extracted,
35 # ie, 'translated', 'fuzzy', or 'untranslated'.
37 # extract_number fills var $number with this number, or sets it to zero if the
38 # word is not found in the string.
40 test $# -eq 2 || error 'extract_number expects 2 args'
43 echo $1 | grep $2 >/dev/null || return
44 # It /is/ safe to use 'Z' as a delimiter here.
45 number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2/Z\1Z/" | cut -d 'Z' -f 2`
49 # $template is used by run_msgfmt, below, to fill $output. The function extracts
50 # the appropriate values from the data.
51 template="array ( 'langcode' => 'LC',
52 \"msg_tr\" => TR, \"msg_fu\" => FU, \"msg_nt\" => NT,
53 \"translator\" => \"AUTHOR\", \"email\" => \"EMAIL\",
54 \"date\" => \"DATE\" )"
58 # $1 is the name of the po file.
60 # The function runs msgfmt on it and fills var $output.
61 # All other variables created in the function are unset on exit.
63 test $# -eq 1 || error 'run_msgfmt expects 1 arg'
67 warning "File $1 does not exist"
74 gmofile=`echo $pofile | sed 's/po$/gmo/'`
75 test $pofile != '' -a $pofile != $gmofile || {
76 warning "File $1 is not a po file"
77 unset origdir dir pofile gmofile
84 langcode=`echo $pofile | sed 's/\.po$//'`
86 # Searching for a string of the form
87 # '"PO-Revision-Date: 2003-01-18 03:00+0100\n"'
88 date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2`
90 # Searching for a string of the form
91 # '"Last-Translator: Michael Schmitt <Michael.Schmitt@teststep.org>\n"'
94 input=`grep "Last-Translator" $pofile` && {
95 input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-`
97 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
98 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
102 # Run msgfmt on the pofile, filling $message with the raw info.
103 message=`$msgfmt --statistics -o $gmofile $pofile 2>&1 | grep "^[1-9]"` || {
104 warning "Unable to run msgfmt successfully on file $1"
106 unset origdir pofile gmofile
111 extract_number "$message" 'translated'
114 extract_number "$message" 'fuzzy'
117 extract_number "$message" 'untranslated'
121 output=`echo "$template" | sed "s/LC/$langcode/; \
122 s/TR/$translated/; s/FU/$fuzzy/; s/NT/$untranslated/; \
123 s/AUTHOR/$translator/; s/EMAIL/$email/; s/DATE/$date/"`
125 unset langcode date translator email untranslated fuzzy translated
131 # The head of the generated php file.
135 // What's the title of the page?
136 \$title = "LyX i18n";
137 // What's the short name of the page in the navigation bar?
139 // Who is the author?
140 \$author="Michael Schmitt";
141 // Full name of the file (relative path from LyX home page -- i.e., it should
142 // be "foo.php3" or "bar/foo.php3")
143 \$file_full="i18n.php3";
145 include("start.php3");
147 error_reporting(E_ALL);
156 # The foot of the generated php file.
176 'pt' => 'Portuguese',
186 \$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt'];
188 function cmp (\$a, \$b) {
189 if (\$a['msg_tr'] == \$b['msg_tr']) {
192 return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1;
195 usort (\$podata, "cmp");
199 The following table details the current state of the translations of the
200 LyX GUI for the main LyX development branch (currently 1.3.0cvs).
201 Unfortunately, only a few languages are well-supported. The LyX term may,
202 therefore, decide to exclude some of the translations from a formal
203 release in order not to confuse the user with a strongly mixed-language
210 <li><i>Translated:</i> The number of translated messages</li>
211 <li><i>Fuzzy:</i> The number of fuzzy messages; these are not considered
212 for LyX output but solely serve as a hint for the translators</li>
213 <li><i>Untranslated:</i> The number of untranslated messages; the
214 default language (i.e., English) will be used in the LyX outputs</li>
216 <table class="center" frame="box" rules="all" border="2" cellpadding="5">
222 <td>Untranslated</td>
223 <td>Revision Date</td>
229 while (list(\$foo,\$info) = each(\$podata)) {
232 if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) {
233 \$style="style='background:#009900'";
234 } else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) {
235 \$style="style='background:#AAAA00'";
237 \$style="style='background:#AA3333'";
240 print "<td \$style>" . \$lang[\$info['langcode']] . "</td>";
242 print "<td \$style align=\"right\">" . \$info['msg_tr'] . "</td>";
244 print "<td \$style align=\"right\">";
245 if (isset(\$info['msg_fu'])) {
246 print \$info['msg_fu'];
252 print "<td \$style align=\"right\">";
253 if (isset(\$info['msg_nt'])) {
254 print \$info['msg_nt'];
260 print "<td \$style align=\"center\">" . \$info['date'] . "</td>";
262 print "<td \$style>";
263 if (\$info['email'] == "") {
264 print \$info['translator'];
266 print "<a href=\"mailto:" . \$info['email'] . "\">" .
267 \$info['translator'] . "</a>";
283 # The main body of the script
284 msgfmt=`which msgfmt`
285 test $msgfmt != '' || error "Unable to find 'msgfmt'. Cannot proceed."
293 if [ $# -eq 0 ]; then