2003-01-24 12:04:14 +00:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
# file postats.sh
|
|
|
|
#
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
#
|
|
|
|
# author: Michael Schmitt, michael.schmitt@teststep.org
|
|
|
|
#
|
2003-01-27 16:15:19 +00:00
|
|
|
# This script extracts some information from the po file headers (last
|
2003-01-24 12:04:14 +00:00
|
|
|
# translator, revision date), generates the corresponding gmo files
|
|
|
|
# to retrieve the number of translated/fuzzy/untranslated messages,
|
|
|
|
# and generates a PHP web page.
|
|
|
|
#
|
|
|
|
# Invocation:
|
|
|
|
# postats.sh po_files > "pathToWebPages"/i18n.php3
|
|
|
|
|
2005-03-24 15:57:38 +00:00
|
|
|
# modifiy this when you change version
|
|
|
|
# Note that an empty lyx_branch variable (ie cvs HEAD)
|
|
|
|
# will "do the right thing".
|
|
|
|
lyx_version=1.4.0cvs
|
|
|
|
lyx_branch=
|
|
|
|
|
|
|
|
|
|
|
|
# GNU sed and grep have real problems dealing with 8-bit characters
|
|
|
|
# in UTF-8 encoded environments.
|
|
|
|
unset LANG
|
2005-07-17 23:39:49 +00:00
|
|
|
LANGUAGE=C
|
2003-01-29 16:29:28 +00:00
|
|
|
|
|
|
|
warning () {
|
|
|
|
echo $* 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-28 23:39:57 +00:00
|
|
|
error () {
|
2003-01-29 16:29:28 +00:00
|
|
|
warning $*
|
2003-01-28 23:39:57 +00:00
|
|
|
exit 1
|
|
|
|
}
|
2003-01-24 12:04:14 +00:00
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
|
2003-01-28 23:39:57 +00:00
|
|
|
# $1 is a string like
|
|
|
|
# '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.'
|
2003-01-29 16:29:28 +00:00
|
|
|
# Any one of these substrings may not appear if the associated number is 0.
|
2004-10-28 14:35:53 +00:00
|
|
|
#
|
2003-01-28 23:39:57 +00:00
|
|
|
# $2 is the word following the number to be extracted,
|
|
|
|
# ie, 'translated', 'fuzzy', or 'untranslated'.
|
2003-01-29 16:29:28 +00:00
|
|
|
#
|
|
|
|
# extract_number fills var $number with this number, or sets it to zero if the
|
2003-01-28 23:39:57 +00:00
|
|
|
# word is not found in the string.
|
|
|
|
extract_number () {
|
|
|
|
test $# -eq 2 || error 'extract_number expects 2 args'
|
2003-01-24 12:04:14 +00:00
|
|
|
|
2003-01-28 23:39:57 +00:00
|
|
|
number=0
|
|
|
|
echo $1 | grep $2 >/dev/null || return
|
2003-01-28 23:56:30 +00:00
|
|
|
# It /is/ safe to use 'Z' as a delimiter here.
|
2003-01-29 16:29:28 +00:00
|
|
|
number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2/Z\1Z/" | cut -d 'Z' -f 2`
|
2003-01-28 23:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
# $template is used by run_msgfmt, below, to fill $output. The function extracts
|
|
|
|
# the appropriate values from the data.
|
|
|
|
template="array ( 'langcode' => 'LC',
|
|
|
|
\"msg_tr\" => TR, \"msg_fu\" => FU, \"msg_nt\" => NT,
|
|
|
|
\"translator\" => \"AUTHOR\", \"email\" => \"EMAIL\",
|
|
|
|
\"date\" => \"DATE\" )"
|
|
|
|
readonly template
|
2003-01-28 23:39:57 +00:00
|
|
|
|
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
# $1 is the name of the po file.
|
|
|
|
#
|
|
|
|
# The function runs msgfmt on it and fills var $output.
|
|
|
|
# All other variables created in the function are unset on exit.
|
|
|
|
run_msgfmt () {
|
|
|
|
test $# -eq 1 || error 'run_msgfmt expects 1 arg'
|
2003-01-28 23:39:57 +00:00
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
output=
|
|
|
|
test -f $1 || {
|
2004-10-28 14:35:53 +00:00
|
|
|
warning "File $1 does not exist"
|
2003-01-28 23:39:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
origdir=`pwd`
|
|
|
|
dir=`dirname $1`
|
|
|
|
pofile=`basename $1`
|
2003-01-28 23:39:57 +00:00
|
|
|
gmofile=`echo $pofile | sed 's/po$/gmo/'`
|
|
|
|
test $pofile != '' -a $pofile != $gmofile || {
|
2004-10-28 14:35:53 +00:00
|
|
|
warning "File $1 is not a po file"
|
2003-01-29 16:29:28 +00:00
|
|
|
unset origdir dir pofile gmofile
|
2003-01-28 23:39:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cd $dir
|
2003-01-29 16:29:28 +00:00
|
|
|
unset dir
|
2003-01-28 23:39:57 +00:00
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
langcode=`echo $pofile | sed 's/\.po$//'`
|
2003-01-28 23:39:57 +00:00
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
# Searching for a string of the form
|
|
|
|
# '"PO-Revision-Date: 2003-01-18 03:00+0100\n"'
|
|
|
|
date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2`
|
|
|
|
|
|
|
|
# Searching for a string of the form
|
|
|
|
# '"Last-Translator: Michael Schmitt <Michael.Schmitt@teststep.org>\n"'
|
|
|
|
translator=
|
|
|
|
email=
|
2003-01-28 23:39:57 +00:00
|
|
|
input=`grep "Last-Translator" $pofile` && {
|
|
|
|
input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-`
|
|
|
|
|
|
|
|
translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
|
|
|
|
email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
|
|
|
|
}
|
2003-01-29 16:29:28 +00:00
|
|
|
unset input
|
|
|
|
|
2005-03-24 15:57:38 +00:00
|
|
|
# Does $translator contain 8-bit characters?
|
|
|
|
TAB=' '
|
|
|
|
echo $translator | grep "[^${TAB} -~]" >/dev/null && {
|
|
|
|
# If so, grab the encoding from the po file.
|
|
|
|
charset=`sed -n '/Content-Type/{s/.*charset=//;s/\\\\n" *$//p;q}' $pofile`
|
|
|
|
# Use recode to generate HTML character codes for the 8-bit
|
|
|
|
# characters.
|
|
|
|
translator=`echo $translator | recode "${charset}..h4"` || exit 1
|
|
|
|
# The ampersands in the $translator entries will mess things
|
|
|
|
# up unless we escape 'em.
|
|
|
|
translator=`echo $translator | sed 's/&/\\\&/g'`
|
|
|
|
}
|
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
# Run msgfmt on the pofile, filling $message with the raw info.
|
|
|
|
message=`$msgfmt --statistics -o $gmofile $pofile 2>&1 | grep "^[1-9]"` || {
|
|
|
|
warning "Unable to run msgfmt successfully on file $1"
|
|
|
|
cg $origdir
|
|
|
|
unset origdir pofile gmofile
|
|
|
|
return
|
|
|
|
}
|
|
|
|
unset pofile gmofile
|
|
|
|
|
|
|
|
extract_number "$message" 'translated'
|
|
|
|
translated=$number
|
|
|
|
|
|
|
|
extract_number "$message" 'fuzzy'
|
|
|
|
fuzzy=$number
|
|
|
|
|
|
|
|
extract_number "$message" 'untranslated'
|
|
|
|
untranslated=$number
|
|
|
|
unset message number
|
|
|
|
|
|
|
|
output=`echo "$template" | sed "s/LC/$langcode/; \
|
|
|
|
s/TR/$translated/; s/FU/$fuzzy/; s/NT/$untranslated/; \
|
|
|
|
s/AUTHOR/$translator/; s/EMAIL/$email/; s/DATE/$date/"`
|
|
|
|
|
|
|
|
unset langcode date translator email untranslated fuzzy translated
|
|
|
|
cd $origdir
|
|
|
|
unset origdir
|
2003-01-28 23:39:57 +00:00
|
|
|
}
|
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
|
|
|
|
# The head of the generated php file.
|
2003-01-28 23:39:57 +00:00
|
|
|
dump_head () {
|
2003-01-24 12:04:14 +00:00
|
|
|
cat <<EOF
|
2003-01-27 16:15:19 +00:00
|
|
|
<?
|
2003-01-24 12:04:14 +00:00
|
|
|
// What's the title of the page?
|
|
|
|
\$title = "LyX i18n";
|
|
|
|
// What's the short name of the page in the navigation bar?
|
|
|
|
\$item="i18n";
|
|
|
|
// Who is the author?
|
|
|
|
\$author="Michael Schmitt";
|
|
|
|
// Full name of the file (relative path from LyX home page -- i.e., it should
|
|
|
|
// be "foo.php3" or "bar/foo.php3")
|
|
|
|
\$file_full="i18n.php3";
|
|
|
|
|
|
|
|
include("start.php3");
|
|
|
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
?>
|
|
|
|
|
2003-01-28 23:39:57 +00:00
|
|
|
<?
|
|
|
|
\$podata = array (
|
|
|
|
EOF
|
|
|
|
}
|
2003-01-24 12:04:14 +00:00
|
|
|
|
|
|
|
|
2003-01-29 16:29:28 +00:00
|
|
|
# The foot of the generated php file.
|
2003-01-28 23:39:57 +00:00
|
|
|
dump_tail () {
|
2005-03-24 15:57:38 +00:00
|
|
|
|
|
|
|
test "$lyx_branch" = "" && {
|
|
|
|
branch_tag=""
|
|
|
|
} || {
|
|
|
|
branch_tag="?only_with_tag=$lyx_branch"
|
|
|
|
}
|
|
|
|
|
2003-01-24 12:04:14 +00:00
|
|
|
cat <<EOF
|
2003-01-29 16:29:28 +00:00
|
|
|
<?
|
|
|
|
\$lang = array(
|
|
|
|
'bg' => 'Bulgarian',
|
|
|
|
'ca' => 'Catalan',
|
|
|
|
'cs' => 'Czech',
|
|
|
|
'da' => 'Danish',
|
|
|
|
'de' => 'German',
|
|
|
|
'es' => 'Spanish',
|
|
|
|
'eu' => 'Basque',
|
|
|
|
'fi' => 'Finnish',
|
|
|
|
'fr' => 'French',
|
|
|
|
'he' => 'Hebrew',
|
|
|
|
'hu' => 'Hungarian',
|
|
|
|
'it' => 'Italian',
|
|
|
|
'nl' => 'Dutch',
|
2005-03-24 15:57:38 +00:00
|
|
|
'nn' => 'Nynorsk',
|
2003-01-29 16:29:28 +00:00
|
|
|
'no' => 'Norwegian',
|
|
|
|
'pl' => 'Polish',
|
|
|
|
'pt' => 'Portuguese',
|
|
|
|
'ro' => 'Romanian',
|
|
|
|
'ru' => 'Russian',
|
|
|
|
'sk' => 'Slovak',
|
|
|
|
'sl' => 'Slovenian',
|
|
|
|
'sv' => 'Swedish',
|
|
|
|
'tr' => 'Turkish',
|
|
|
|
'wa' => 'Walloon'
|
|
|
|
);
|
|
|
|
|
|
|
|
\$noOfMsg = \$podata[0]['msg_tr'] + \$podata[0]['msg_fu'] + \$podata[0]['msg_nt'];
|
|
|
|
|
|
|
|
function cmp (\$a, \$b) {
|
|
|
|
if (\$a['msg_tr'] == \$b['msg_tr']) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (\$a['msg_tr'] > \$b['msg_tr']) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
usort (\$podata, "cmp");
|
|
|
|
?>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
The following table details the current state of the translations of the
|
2005-03-24 15:57:38 +00:00
|
|
|
LyX GUI for the LyX stable branch (currently $lyx_version).
|
|
|
|
Unfortunately, only a few languages are well-supported. The LyX team may,
|
2003-01-29 16:29:28 +00:00
|
|
|
therefore, decide to exclude some of the translations from a formal
|
|
|
|
release in order not to confuse the user with a strongly mixed-language
|
|
|
|
interface.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Explanation:
|
|
|
|
</p>
|
|
|
|
<ul>
|
|
|
|
<li><i>Translated:</i> The number of translated messages</li>
|
|
|
|
<li><i>Fuzzy:</i> The number of fuzzy messages; these are not considered
|
|
|
|
for LyX output but solely serve as a hint for the translators</li>
|
|
|
|
<li><i>Untranslated:</i> The number of untranslated messages; the
|
|
|
|
default language (i.e., English) will be used in the LyX outputs</li>
|
|
|
|
</ul>
|
|
|
|
<table class="center" frame="box" rules="all" border="2" cellpadding="5">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td>Language</td>
|
|
|
|
<td>Translated</td>
|
|
|
|
<td>Fuzzy</td>
|
|
|
|
<td>Untranslated</td>
|
|
|
|
<td>Revision Date</td>
|
|
|
|
<td>Translator</td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<?
|
|
|
|
while (list(\$foo,\$info) = each(\$podata)) {
|
|
|
|
print "<tr>";
|
|
|
|
|
|
|
|
if ( \$info['msg_tr'] > \$noOfMsg * 2 / 3 ) {
|
|
|
|
\$style="style='background:#009900'";
|
|
|
|
} else if ( \$info['msg_tr'] > \$noOfMsg / 2 ) {
|
|
|
|
\$style="style='background:#AAAA00'";
|
|
|
|
} else {
|
|
|
|
\$style="style='background:#AA3333'";
|
|
|
|
}
|
2005-03-24 15:57:38 +00:00
|
|
|
print "<td \$style>" ;
|
2003-01-29 16:29:28 +00:00
|
|
|
|
2005-03-24 15:57:38 +00:00
|
|
|
print "<a href=\"http://www.lyx.org/cgi-bin/viewcvs.cgi/lyx-devel/po/" . \$info['langcode'] . ".po$branch_tag\">" . \$lang[\$info['langcode']] . "</a></td>";
|
2003-01-29 16:29:28 +00:00
|
|
|
|
|
|
|
print "<td \$style align=\"right\">" . \$info['msg_tr'] . "</td>";
|
|
|
|
|
|
|
|
print "<td \$style align=\"right\">";
|
|
|
|
if (isset(\$info['msg_fu'])) {
|
|
|
|
print \$info['msg_fu'];
|
|
|
|
} else {
|
|
|
|
print "0";
|
|
|
|
}
|
|
|
|
print "</td>";
|
|
|
|
|
|
|
|
print "<td \$style align=\"right\">";
|
|
|
|
if (isset(\$info['msg_nt'])) {
|
|
|
|
print \$info['msg_nt'];
|
|
|
|
} else {
|
|
|
|
print "0";
|
|
|
|
}
|
|
|
|
print "</td>";
|
|
|
|
|
|
|
|
print "<td \$style align=\"center\">" . \$info['date'] . "</td>";
|
|
|
|
|
|
|
|
print "<td \$style>";
|
|
|
|
if (\$info['email'] == "") {
|
|
|
|
print \$info['translator'];
|
|
|
|
} else {
|
|
|
|
print "<a href=\"mailto:" . \$info['email'] . "\">" .
|
|
|
|
\$info['translator'] . "</a>";
|
|
|
|
}
|
|
|
|
print "</td>";
|
|
|
|
|
|
|
|
print "</tr>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<?
|
|
|
|
include("end.php3");
|
|
|
|
?>
|
2003-01-24 12:04:14 +00:00
|
|
|
EOF
|
2003-01-28 23:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# The main body of the script
|
2003-01-29 16:29:28 +00:00
|
|
|
msgfmt=`which msgfmt`
|
2004-10-28 14:35:53 +00:00
|
|
|
test $msgfmt != '' || error "Unable to find 'msgfmt'. Cannot proceed."
|
2003-01-28 23:39:57 +00:00
|
|
|
|
|
|
|
dump_head
|
|
|
|
|
|
|
|
while [ $# -ne 0 ]
|
|
|
|
do
|
2003-01-29 16:29:28 +00:00
|
|
|
run_msgfmt $1
|
2003-01-28 23:39:57 +00:00
|
|
|
shift
|
|
|
|
if [ $# -eq 0 ]; then
|
2003-01-29 16:29:28 +00:00
|
|
|
echo "${output});"
|
|
|
|
echo '?>'
|
2003-01-28 23:39:57 +00:00
|
|
|
else
|
2003-01-29 16:29:28 +00:00
|
|
|
echo "${output},"
|
|
|
|
echo
|
2003-01-28 23:39:57 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
dump_tail
|
2003-01-29 16:29:28 +00:00
|
|
|
# The end
|