| 1 |
#!/usr/bin/perl -w
|
| 2 |
#
|
| 3 |
# Check translation status
|
| 4 |
#
|
| 5 |
# This program is copyright 2004 by Javier Fernandez-Sanguino <jfs@debian.org>
|
| 6 |
#
|
| 7 |
# This program is free software; you can redistribute it and/or modify
|
| 8 |
# it under the terms of the GNU General Public License as published by
|
| 9 |
# the Free Software Foundation; either version 2 of the License, or
|
| 10 |
# (at your option) any later version.
|
| 11 |
#
|
| 12 |
# This program is distributed in the hope that it will be useful,
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
# GNU General Public License for more details.
|
| 16 |
#
|
| 17 |
# You should have received a copy of the GNU General Public License
|
| 18 |
# along with this program; if not, write to the Free Software
|
| 19 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 20 |
#
|
| 21 |
# For more information please see
|
| 22 |
# http://www.gnu.org/licenses/licenses.html#GPL
|
| 23 |
#
|
| 24 |
|
| 25 |
# Enable for debugging
|
| 26 |
$DEBUG = 1;
|
| 27 |
|
| 28 |
# Program configuration
|
| 29 |
$ORIGLANG="en";
|
| 30 |
$LANGS="ca cs da de es fi fr it ja ko lt nl pt pt_BR ro ru sk sv vi zh_CN zh_TW";
|
| 31 |
|
| 32 |
$|=1;
|
| 33 |
|
| 34 |
$origrelease = find_current_release();
|
| 35 |
|
| 36 |
if ( $origrelease == 0 ) {
|
| 37 |
print STDERR "Aborting: Could not find what the current release number is!\n";
|
| 38 |
exit 1;
|
| 39 |
}
|
| 40 |
print "DEBUG: Release is $origrelease\n" if $DEBUG;
|
| 41 |
|
| 42 |
my $minor_orig_release = minor_version($origrelease);
|
| 43 |
foreach $lang (split(" ",$LANGS)) {
|
| 44 |
$langrelease = find_lang_release($lang);
|
| 45 |
if ( $langrelease eq "NONE" ) {
|
| 46 |
if ( check_po($lang) < 0 ) {
|
| 47 |
print "ERROR: [ $lang ] has no SGML nor PO files\n";
|
| 48 |
}
|
| 49 |
} elsif ( $langrelease ne "EMPTY" ) {
|
| 50 |
my $minor_lang_release = minor_version($langrelease);
|
| 51 |
if ( $minor_lang_release < $minor_orig_release ) {
|
| 52 |
print "$lang OUT OF DATE ($langrelease)\n";
|
| 53 |
} elsif ( $minor_lang_release > $minor_orig_release ) {
|
| 54 |
print "ERROR: [ $lang ] has a document version higher than current ($langrelease)\n";
|
| 55 |
} elsif ( $langrelease eq $origrelease ) {
|
| 56 |
print "$lang is up to date\n";
|
| 57 |
}
|
| 58 |
} else {
|
| 59 |
print "ERROR: [ $lang ] could not find document version information in headers\n";
|
| 60 |
}
|
| 61 |
|
| 62 |
}
|
| 63 |
|
| 64 |
exit 0;
|
| 65 |
|
| 66 |
sub find_current_release {
|
| 67 |
my $release = 0;
|
| 68 |
open (RELEASE, "$ORIGLANG/release-notes.en.sgml") or die ("Could not open release notes: $!");
|
| 69 |
while ($release == 0 and $line = <RELEASE> ) {
|
| 70 |
chomp $line;
|
| 71 |
$release = $1 if ( $line =~ /v ([\d\.]+) / ) ;
|
| 72 |
}
|
| 73 |
close RELEASE;
|
| 74 |
return $release;
|
| 75 |
}
|
| 76 |
|
| 77 |
sub find_lang_release {
|
| 78 |
my ($LANG) = @_;
|
| 79 |
my $release = "EMPTY";
|
| 80 |
# No SGML file or using PO files for translation
|
| 81 |
if ( ! -e "$LANG/release-notes.$LANG.sgml" or -e "$LANG/release-notes.$LANG.po" ) {
|
| 82 |
return "NONE";
|
| 83 |
}
|
| 84 |
open (RELEASE, "$LANG/release-notes.$LANG.sgml") or die ("Could not open release notes for $LANG: $!");
|
| 85 |
while ($release eq "EMPTY" and $line = <RELEASE> ) {
|
| 86 |
chomp $line;
|
| 87 |
# The header should be
|
| 88 |
# <!-- Translation based on English version XXX -->
|
| 89 |
# but some do not comply with this
|
| 90 |
$release = $1 if ( $line =~ /based on English version ([\d\.]+) / ) ;
|
| 91 |
$release = $1 if ( $line =~ /original version: ([\d\.]+) / ) ;
|
| 92 |
}
|
| 93 |
close RELEASE;
|
| 94 |
return $release;
|
| 95 |
}
|
| 96 |
|
| 97 |
sub minor_version {
|
| 98 |
my ($version) = @_;
|
| 99 |
my $minor = 0;
|
| 100 |
$minor = $1 if ($version =~ /(\d+)$/ ) ;
|
| 101 |
return $minor;
|
| 102 |
}
|
| 103 |
|
| 104 |
sub check_po {
|
| 105 |
my ($LANG) = @_;
|
| 106 |
# Return if no PO files for translation available
|
| 107 |
return -1 if ( ! -e "$LANG/release-notes.$LANG.po" );
|
| 108 |
# or if LANG is not what we expected
|
| 109 |
return -1 if ( $LANG !~ /^[\w\_]+$/ ) ;
|
| 110 |
# or if we don't have gettext available
|
| 111 |
if ( ! -e "/usr/bin/msgfmt") {
|
| 112 |
print "WARN: Cannot check PO translation for $LANG, gettext not installed\n";
|
| 113 |
return -1;
|
| 114 |
}
|
| 115 |
$stats = `LC_ALL=C /usr/bin/msgfmt --stat -c -o /dev/null $LANG/release-notes.$LANG.po 2>&1`;
|
| 116 |
print "$LANG PO stats: $stats";
|
| 117 |
if ( $stats =~ /fuzzy/ or $stats =~ /untranslated/ ) {
|
| 118 |
print "\t$LANG PO translation OUT OF DATE\n";
|
| 119 |
} else {
|
| 120 |
print "\t$LANG PO translation up to date\n";
|
| 121 |
}
|
| 122 |
return 0;
|
| 123 |
}
|