[gnome-i18n] Bug 523912 — Automated translation diff tool
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-i18n] Bug 523912 — Automated translation diff tool
- Date: Fri, 29 Jul 2011 23:04:56 +0000 (UTC)
commit 6a1bd4f8861d16ff7c478db3fb06df7fe2e78cc1
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Aug 27 17:40:44 2010 +0100
Bug 523912 â Automated translation diff tool
Add a --check mode to en_GB.pl to allow automated checking of manual
translations. This highlights errors in the manual translation, as well as
errors in the C locale string which were fixed in the manual translation.
Closes: bgo#523912
en_GB/en_GB.pl | 102 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 70 insertions(+), 32 deletions(-)
---
diff --git a/en_GB/en_GB.pl b/en_GB/en_GB.pl
index 1a64713..44fe8b2 100755
--- a/en_GB/en_GB.pl
+++ b/en_GB/en_GB.pl
@@ -67,7 +67,7 @@ use strict;
use warnings;
use Time::gmtime;
use Term::ReadLine;
-use vars qw($msg_str $msg_id $locale $rl);
+use vars qw($msg_str $msg_id $locale $rl $check_mode);
sub do_trans {
my ($tf, $tt) = @_;
@@ -125,26 +125,45 @@ sub query_trans {
}
sub translate() {
- if (!($msg_str eq "\"\"\n")) {
-
- my $date = sprintf("%04i-%02i-%02i %02i:%02i+0000", gmtime()->year+1900,
- gmtime()->mon+1, gmtime()->mday, gmtime()->hour, gmtime()->min);
-
- $msg_str =~ s/YEAR-MO-DA HO:MI\+ZONE/$date/;
- $msg_str =~ s/YEAR-MO-DA HO:MI\+DIST/$date/;
- $msg_str =~ s/FULL NAME <EMAIL\ ADDRESS>/Abigail Brady <morwen\ evilmagic org>/;
- $msg_str =~ s/CHARSET/UTF-8/;
- $msg_str =~ s/ENCODING/8-bit/;
- $msg_str =~ s/LANGUAGE <LL\ li org>//;
- $msg_str =~ s/Plural-Forms: nplurals=INTEGER; plural=EXPRESSION/Plural-Forms: nplurals=2; plural=n != 1;/;
- return;
- }
+ my $old_msg_str;
+
+ if (!$check_mode) {
+ # We're doing a normal translation
+ if (!($msg_str eq "\"\"\n")) {
+ my $date = sprintf("%04i-%02i-%02i %02i:%02i+0000", gmtime()->year+1900,
+ gmtime()->mon+1, gmtime()->mday, gmtime()->hour, gmtime()->min);
+
+ $msg_str =~ s/YEAR-MO-DA HO:MI\+ZONE/$date/;
+ $msg_str =~ s/YEAR-MO-DA HO:MI\+DIST/$date/;
+ $msg_str =~ s/FULL NAME <EMAIL\ ADDRESS>/Abigail Brady <morwen\ evilmagic org>/;
+ $msg_str =~ s/CHARSET/UTF-8/;
+ $msg_str =~ s/ENCODING/8-bit/;
+ $msg_str =~ s/LANGUAGE <LL\ li org>//;
+ $msg_str =~ s/Plural-Forms: nplurals=INTEGER; plural=EXPRESSION/Plural-Forms: nplurals=2; plural=n != 1;/;
+ return;
+ }
- # Epiphany-style contexting
- # FIXME we should save the context and pass it
- if ( $msg_id =~ m/^.*\|(.*)$/ ) {
- $msg_str = "\"".$1."\n";
+ # Epiphany-style contexting
+ # FIXME we should save the context and pass it
+ if ( $msg_id =~ m/^.*\|(.*)$/ ) {
+ $msg_str = "\"".$1."\n";
+ } else {
+ $msg_str = $msg_id;
+ }
} else {
+ # We're checking for differences between a translation and the original strings
+ # Skip the header and translation-credits strings (they're boring)
+ if ($msg_id eq "\"\"\n" or $msg_id eq "\"translator-credits\"\n" or $msg_id eq "\"translator_credits\"\n") {
+ return;
+ }
+
+ if ($msg_str eq "\"\"\n") {
+ print "\nUntranslated string\n";
+ print "C string: ${msg_id}\n\n";
+ return;
+ }
+
+ $old_msg_str = $msg_str;
$msg_str = $msg_id;
}
@@ -318,6 +337,13 @@ sub translate() {
# if ($msg_str eq $msg_id) {
# $msg_str = "\"\"\n";
# }
+
+ if ($check_mode and !($old_msg_str eq $msg_str)) {
+ print "C string: ${msg_id}";
+ print "Automated translation: ${msg_str}";
+ print "Manual translation: ${old_msg_str}";
+ print "\n";
+ }
}
# Modes:
@@ -327,6 +353,7 @@ sub translate() {
# 4 = adding to plural msgstr
my $mode = 0;
+$check_mode = ($#ARGV eq 1 and $ARGV[0] eq "--check");
$rl = Term::ReadLine->new("String Replacement");
$locale = $ENV{'LANG'};
$locale =~ s/\..*//g;
@@ -335,8 +362,9 @@ my $msg_id2 = "";
my $msg_str2 = "";
$msg_str = "";
-while (<>) {
- if (/^#/) {
+open (po_file, $ARGV[$#ARGV]);
+while (<po_file>) {
+ if (/^#/ and !$check_mode) {
s/SOME DESCRIPTIVE TITLE/English (British) translation/;
my $year = gmtime()->year+1900;
s/YEAR/$year/;
@@ -376,37 +404,47 @@ while (<>) {
if (defined $msg_id2 && $msg_id2 ne "") {
translate();
- print "msgid $msg_id";
- print "msgid_plural $msg_id2";
- print "msgstr[0] $msg_str";
+ if (!$check_mode) {
+ print "msgid $msg_id";
+ print "msgid_plural $msg_id2";
+ print "msgstr[0] $msg_str";
+ }
$msg_id = $msg_id2;
$msg_str = $msg_str2;
translate();
- print "msgstr[1] $msg_str";
+ if (!$check_mode) {
+ print "msgstr[1] $msg_str";
+ }
$msg_id = "";
$msg_id2 = "";
$msg_str = "";
$msg_str2 = "";
} elsif ($msg_id || $msg_str) {
translate();
- print "msgid $msg_id";
- print "msgstr $msg_str";
+ if (!$check_mode) {
+ print "msgid $msg_id";
+ print "msgstr $msg_str";
+ }
$msg_id = "";
$msg_id2 = "";
$msg_str = "";
$msg_str2 = "";
}
- print $line;
- }
+ if (!$check_mode) {
+ print $line;
+ }
+ }
}
-
+close (po_file);
if ($msg_id || $msg_str) {
translate();
- print "msgid $msg_id";
- print "msgstr $msg_str";
+ if (!$check_mode) {
+ print "msgid $msg_id";
+ print "msgstr $msg_str";
+ }
$msg_id = "";
$msg_str = "";
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]