]> git.lyx.org Git - lyx.git/blob - po/postats.sh
f30084ca2ea4d2b27e8d97246cf750afdfe23df7
[lyx.git] / po / postats.sh
1 #! /bin/sh
2
3 # file postats.sh
4 #
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7 #
8 # author: Michael Schmitt, michael.schmitt@teststep.org
9 #
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.
14 #
15 # Invocation:
16 #    postats.sh po_files > "pathToWebPages"/i18n.php3
17
18 error () {
19         while [ $# -ne 0 ]
20         do
21                 echo $1
22                 shift
23         done
24         exit 1
25 }
26
27 # $1 is a string like
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.
33 extract_number () {
34         test $# -eq 2 || error 'extract_number expects 2 args'
35
36         number=0
37         echo $1 | grep $2 >/dev/null || return
38         number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2.*/Z\1/" | cut -d 'Z' -f 2`
39 }
40
41
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 
44 # fill var $output
45 run_msgfmt () {
46         test $# -eq 2 || error 'run_msgfmt expects 2 args'
47
48         rm -f $gmofile
49         message=`$msgfmt --statistics -o $gmofile $1 2>&1 | grep "^[1-9]"`
50         #message=`make $gmofile 2>&1 | grep "^[1-9]"`
51         
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
58 }
59
60
61 # Passed the name of the .po file
62 dump_stats () {
63         test $# -eq 1 || error 'dump_stats expects 1 arg'
64
65         file=$1
66         test -f $file || {
67                 echo "File $file does not exist"
68                 return
69         }
70
71         dir=`dirname $file`
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"
76                 return
77         }
78
79         (
80         cd $dir
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
84         # file
85         run_msgfmt $pofile $gmofile
86
87         # earching for a string of the form
88         # '"Last-Translator: Michael Schmitt <Michael.Schmitt@teststep.org>\n"'
89         translator='"translator" => ""'
90         email='"email" => ""'
91
92         input=`grep "Last-Translator" $pofile` && {
93                 input=`echo $input | sed 's/  */ /g' | cut -d ' ' -f 2-`
94
95                 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
96                 translator='"translator" => "'$translator'"'
97
98                 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
99                 email='"email" => "'$email'"'
100         }
101         
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'"'
106
107         langcode=`echo $pofile | sed 's/\.po//'`
108         echo "array ( 'langcode' => '"$langcode"',"
109         echo ${output},
110         echo ${translator}, ${email},
111         echo "${date} )"
112         )
113 }
114
115 dump_head () {
116 cat <<EOF
117 <?
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?
121         \$item="i18n";
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";
127
128         include("start.php3");
129
130         error_reporting(E_ALL);
131 ?>
132
133 <?
134 \$podata = array (
135 EOF
136 }
137
138
139 dump_tail () {
140 cat <<EOF
141         <?
142                 \$lang = array(
143                                 'bg' => 'Bulgarian',
144                                 'ca' => 'Catalan',
145                                 'cs' => 'Czech',
146                                 'da' => 'Danish',
147                                 'de' => 'German',
148                                 'es' => 'Spanish',
149                                 'eu' => 'Basque',
150                                 'fi' => 'Finnish',
151                                 'fr' => 'French',
152                                 'he' => 'Hebrew',
153                                 'hu' => 'Hungarian',
154                                 'it' => 'Italian',
155                                 'nl' => 'Dutch',
156                                 'no' => 'Norwegian',
157                                 'pl' => 'Polish',
158                                 'pt' => 'Portuguese',
159                                 'ro' => 'Romanian',
160                                 'ru' => 'Russian',
161                                 'sk' => 'Slovak',
162                                 'sl' => 'Slovenian',
163                                 'sv' => 'Swedish',
164                                 'tr' => 'Turkish',
165                                 'wa' => 'Wallon'
166                              );
167
168                 \$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt'];
169
170                 function cmp (\$a, \$b) {
171                         if (\$a['msg_tr'] == \$b['msg_tr']) {
172                                 return 0;
173                         }
174                         return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1;
175                 }
176
177                 usort (\$podata, "cmp");
178         ?>
179
180         <p>
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.
187         </p>
188         <p>
189                 Explanation:
190         </p>
191         <ul>
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>
197         </ul>
198         <table class="center" frame="box" rules="all" border="2" cellpadding="5">
199                 <thead>
200                         <tr>
201                                 <td>Language</td>
202                                 <td>Translated</td>
203                                 <td>Fuzzy</td>
204                                 <td>Untranslated</td>
205                                 <td>Revision Date</td>
206                                 <td>Translator</td>
207                         </tr>
208                 </thead>
209                 <tbody>
210                         <?
211                                 while (list(\$foo,\$info) = each(\$podata)) {
212                                         print "<tr>";
213
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'";
218                                         } else {
219                                                 \$style="style='background:#AA3333'";
220                                         }
221
222                                         print "<td \$style>" . \$lang[\$info['langcode']] . "</td>";
223
224                                         print "<td \$style align=\"right\">" . \$info['msg_tr'] . "</td>";
225
226                                         print "<td \$style align=\"right\">";
227                                         if (isset(\$info['msg_fu'])) {
228                                                 print \$info['msg_fu'];
229                                         } else {
230                                                 print "0";
231                                         }
232                                         print "</td>";
233
234                                         print "<td \$style align=\"right\">";
235                                         if (isset(\$info['msg_nt'])) {
236                                                 print \$info['msg_nt'];
237                                         } else {
238                                                 print "0";
239                                         }
240                                         print "</td>";
241
242                                         print "<td \$style align=\"center\">" . \$info['date'] . "</td>";
243
244                                         print "<td \$style>";
245                                         if (\$info['email'] == "") {
246                                                 print \$info['translator'];
247                                         } else {
248                                                 print "<a href=\"mailto:" . \$info['email'] . "\">" .
249                                                       \$info['translator'] . "</a>";
250                                         }
251                                         print "</td>";
252
253                                         print "</tr>\n";
254                                 }
255                         ?>
256                 </tbody>
257         </table>
258         <?
259                 include("end.php3");
260         ?>
261 EOF
262 }
263
264
265 # The main body of the script
266 msgfmt=`type msgfmt | sed 's/msgfmt is *//'`
267 test msgfmt != '' || error "Unable to find 'msgfmt'"
268
269 dump_head
270
271 while [ $# -ne 0 ]
272 do
273         dump_stats $1
274         shift
275         if [ $# -eq 0 ]; then
276             echo ');'
277             echo '?>'
278         else
279             echo ','
280         fi
281 done
282
283 dump_tail
284