summaryrefslogtreecommitdiffstats
path: root/scripts/checktranslation.pl
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2017-10-29 13:30:20 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-10-29 11:01:56 -0700
commit43b1a73022cf4dd80c4df39d381589484d67a655 (patch)
treeb3ad1a59c6a3af7a8bc38335cfd62dbcbbf0b33f /scripts/checktranslation.pl
parent15028fd299e639a5b006c620dfe0e241b22c4163 (diff)
downloadsubsurface-43b1a73022cf4dd80c4df39d381589484d67a655.tar.gz
Check arguments of translation strings
Make sure the arguments of placeholders agree Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'scripts/checktranslation.pl')
-rwxr-xr-xscripts/checktranslation.pl34
1 files changed, 27 insertions, 7 deletions
diff --git a/scripts/checktranslation.pl b/scripts/checktranslation.pl
index 0324ad88a..8c20b9e19 100755
--- a/scripts/checktranslation.pl
+++ b/scripts/checktranslation.pl
@@ -1,7 +1,11 @@
#!/usr/bin/perl -CS
+# Run this script to check if translations messed up format string arguments
+#
+# Usage scripts/checktranslations.pl translations/*ts
+
use strict;
-use utf8;
+use utf8::all;
use XML::TreeBuilder;
foreach my $file_name (@ARGV) {
@@ -9,12 +13,28 @@ foreach my $file_name (@ARGV) {
$tree->parse_file($file_name, ProtocolEncoding => 'UTF-8');
foreach my $string ($tree->find_by_tag_name('message')) {
my $source = $string->find_by_tag_name('source')->as_text;
- my $translation = $string->find_by_tag_name('translation')->as_text;
- next unless $translation =~ /\S/;
- my @source_args = ($source =~ /\%([^\s\-\(\)])/g);
- my @translation_args = ($translation =~ /\%([^\s\-\(\)])/g);
- if (scalar(@source_args) != scalar(@translation_args)) {
- print "$file_name:\n$source\n->\n$translation\n\n";
+ my $translation = $string->find_by_tag_name('translation');
+ if ($translation->find_by_tag_name('numerusform')) {
+ my @all = $translation->find_by_tag_name('numerusform');
+ foreach my $transstring(@all) {
+ &compare($file_name, $source, $transstring->as_text);
+ }
+ } else {
+ &compare($file_name, $source, $translation->as_text);
}
}
}
+
+sub compare {
+ my ($file_name, $src, $trans) = @_;
+
+# print "Checking $src\n";
+ return unless $trans =~ /\S/;
+ my @source_args = sort {$a cmp $b} ($src =~ /\%([^\s\-\(\)\,\.\:])/g);
+ my @translation_args = sort {$a cmp $b} ($trans =~ /\%([^\s\-\(\)\,\.\:])/g);
+# print join("|", @translation_args), " vs ", join("|", @source_args),"\n";
+ unless (join('', @source_args) eq join('', @translation_args)) {
+ print "$file_name:\n$src\n->\n$trans\n\n";
+ }
+}
+