5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # author: Michael Gerz, michael.gerz@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.php
18 # modifiy this when you change version
19 # Note that an empty lyx_branch variable (ie cvs HEAD)
20 # will "do the right thing".
25 # GNU sed and grep have real problems dealing with 8-bit characters
26 # in UTF-8 encoded environments.
42 # '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.'
43 # Any one of these substrings may not appear if the associated number is 0.
45 # $2 is the word following the number to be extracted,
46 # ie, 'translated', 'fuzzy', or 'untranslated'.
48 # extract_number fills var $number with this number, or sets it to zero if the
49 # word is not found in the string.
51 test $# -eq 2 || error 'extract_number expects 2 args'
54 echo $1 | grep $2 >/dev/null || return
55 # It /is/ safe to use 'Z' as a delimiter here.
56 number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2/Z\1Z/" | cut -d 'Z' -f 2`
60 # $template is used by run_msgfmt, below, to fill $output. The function extracts
61 # the appropriate values from the data.
62 template="array ( 'langcode' => 'LC',
63 \"msg_tr\" => TR, \"msg_fu\" => FU, \"msg_nt\" => NT,
64 \"translator\" => \"AUTHOR\", \"email\" => \"EMAIL\",
65 \"date\" => \"DATE\" )"
69 # $1 is the name of the po file.
71 # The function runs msgfmt on it and fills var $output.
72 # All other variables created in the function are unset on exit.
74 test $# -eq 1 || error 'run_msgfmt expects 1 arg'
78 warning "File $1 does not exist"
85 gmofile=`echo $pofile | sed 's/po$/gmo/'`
86 test $pofile != '' -a $pofile != $gmofile || {
87 warning "File $1 is not a po file"
88 unset origdir dir pofile gmofile
95 langcode=`echo $pofile | sed 's/\.po$//'`
97 # Searching for a string of the form
98 # '"PO-Revision-Date: 2003-01-18 03:00+0100\n"'
99 date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2`
101 # Searching for a string of the form
102 # '"Last-Translator: Michael Gerz <Michael.Gerz@teststep.org>\n"'
105 input=`grep "Last-Translator" $pofile` && {
106 input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-`
108 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
109 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
113 # Does $translator contain 8-bit characters?
115 echo $translator | grep "[^${TAB} -~]" >/dev/null && {
116 # If so, grab the encoding from the po file.
117 charset=`sed -n '/Content-Type/{s/.*charset=//;s/\\\\n" *$//p;q}' $pofile`
118 # Use recode to generate HTML character codes for the 8-bit
120 translator=`echo $translator | recode "${charset}..h4"` || exit 1
121 # The ampersands in the $translator entries will mess things
122 # up unless we escape 'em.
123 translator=`echo $translator | sed 's/&/\\\&/g'`
126 # Run msgfmt on the pofile, filling $message with the raw info.
127 message=`$msgfmt --statistics -o $gmofile $pofile 2>&1 | grep "^[1-9]"` || {
128 warning "Unable to run msgfmt successfully on file $1"
130 unset origdir pofile gmofile
135 extract_number "$message" 'translated'
138 extract_number "$message" 'fuzzy'
141 extract_number "$message" 'untranslated'
145 output=`echo "$template" | sed "s/LC/$langcode/; \
146 s/TR/$translated/; s/FU/$fuzzy/; s/NT/$untranslated/; \
147 s/AUTHOR/$translator/; s/EMAIL/$email/; s/DATE/$date/"`
149 unset langcode date translator email untranslated fuzzy translated
155 # The head of the generated php file.
159 // What's the title of the page?
160 \$title = "LyX i18n";
161 // What's the short name of the page in the navigation bar?
163 // Who is the author?
164 \$author="Michael Gerz";
165 // Full name of the file (relative path from LyX home page -- i.e., it should
166 // be "foo.php" or "bar/foo.php")
167 \$file_full="devel/i18n.php";
169 include("start.php");
171 error_reporting(E_ALL);
180 # The foot of the generated php file.
183 test "$lyx_branch" = "" && {
186 branch_tag="branches/$lyx_branch"
209 'pt' => 'Portuguese',
219 \$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt'];
221 function cmp (\$a, \$b) {
222 if (\$a['msg_tr'] == \$b['msg_tr']) {
225 return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1;
228 usort (\$podata, "cmp");
232 The following table details the current state of the translations of the
233 LyX GUI for the LyX stable branch (currently $lyx_version).
234 Unfortunately, only a few languages are well-supported. The LyX team may,
235 therefore, decide to exclude some of the translations from a formal
236 release in order not to confuse the user with a strongly mixed-language
243 <li><i>Translated:</i> The number of translated messages</li>
244 <li><i>Fuzzy:</i> The number of fuzzy messages; these are not considered
245 for LyX output but solely serve as a hint for the translators</li>
246 <li><i>Untranslated:</i> The number of untranslated messages; the
247 default language (i.e., English) will be used in the LyX outputs</li>
249 <table class="center" frame="box" rules="all" border="2" cellpadding="5">
255 <td>Untranslated</td>
256 <td>Revision Date</td>
262 while (list(\$foo,\$info) = each(\$podata)) {
265 if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) {
266 \$style="style='background:#009900'";
267 } else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) {
268 \$style="style='background:#AAAA00'";
270 \$style="style='background:#AA3333'";
272 print "<td \$style>" ;
274 print "<a href=\"http://www.lyx.org/trac/browser/lyx-devel/$branch_tag/po/" . \$info['langcode'] . ".po?format=raw\">" . \$lang[\$info['langcode']] . "</a></td>";
276 print "<td \$style align=\"right\">" . \$info['msg_tr'] . "</td>";
278 print "<td \$style align=\"right\">";
279 if (isset(\$info['msg_fu'])) {
280 print \$info['msg_fu'];
286 print "<td \$style align=\"right\">";
287 if (isset(\$info['msg_nt'])) {
288 print \$info['msg_nt'];
294 print "<td \$style align=\"center\">" . \$info['date'] . "</td>";
296 print "<td \$style>";
297 if (\$info['email'] == "") {
298 print \$info['translator'];
300 print "<a href=\"mailto:" . \$info['email'] . "\">" .
301 \$info['translator'] . "</a>";
317 # The main body of the script
318 msgfmt=`which msgfmt`
319 test $msgfmt != '' || error "Unable to find 'msgfmt'. Cannot proceed."
327 if [ $# -eq 0 ]; then