Skip to content

Commit 43b1a73

Browse files
atdotdedirkhh
authored andcommitted
Check arguments of translation strings
Make sure the arguments of placeholders agree Signed-off-by: Robert C. Helling <[email protected]>
1 parent 15028fd commit 43b1a73

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

scripts/checktranslation.pl

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
#!/usr/bin/perl -CS
22

3+
# Run this script to check if translations messed up format string arguments
4+
#
5+
# Usage scripts/checktranslations.pl translations/*ts
6+
37
use strict;
4-
use utf8;
8+
use utf8::all;
59
use XML::TreeBuilder;
610

711
foreach my $file_name (@ARGV) {
812
my $tree = XML::TreeBuilder->new({'NoExpand' => 0, 'ErrorContext' => 0});
913
$tree->parse_file($file_name, ProtocolEncoding => 'UTF-8');
1014
foreach my $string ($tree->find_by_tag_name('message')) {
1115
my $source = $string->find_by_tag_name('source')->as_text;
12-
my $translation = $string->find_by_tag_name('translation')->as_text;
13-
next unless $translation =~ /\S/;
14-
my @source_args = ($source =~ /\%([^\s\-\(\)])/g);
15-
my @translation_args = ($translation =~ /\%([^\s\-\(\)])/g);
16-
if (scalar(@source_args) != scalar(@translation_args)) {
17-
print "$file_name:\n$source\n->\n$translation\n\n";
16+
my $translation = $string->find_by_tag_name('translation');
17+
if ($translation->find_by_tag_name('numerusform')) {
18+
my @all = $translation->find_by_tag_name('numerusform');
19+
foreach my $transstring(@all) {
20+
&compare($file_name, $source, $transstring->as_text);
21+
}
22+
} else {
23+
&compare($file_name, $source, $translation->as_text);
1824
}
1925
}
2026
}
27+
28+
sub compare {
29+
my ($file_name, $src, $trans) = @_;
30+
31+
# print "Checking $src\n";
32+
return unless $trans =~ /\S/;
33+
my @source_args = sort {$a cmp $b} ($src =~ /\%([^\s\-\(\)\,\.\:])/g);
34+
my @translation_args = sort {$a cmp $b} ($trans =~ /\%([^\s\-\(\)\,\.\:])/g);
35+
# print join("|", @translation_args), " vs ", join("|", @source_args),"\n";
36+
unless (join('', @source_args) eq join('', @translation_args)) {
37+
print "$file_name:\n$src\n->\n$trans\n\n";
38+
}
39+
}
40+

0 commit comments

Comments
 (0)