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