|
1 | 1 | #!/usr/bin/perl -CS |
2 | 2 |
|
| 3 | +# Run this script to check if translations messed up format string arguments |
| 4 | +# |
| 5 | +# Usage scripts/checktranslations.pl translations/*ts |
| 6 | + |
3 | 7 | use strict; |
4 | | -use utf8; |
| 8 | +use utf8::all; |
5 | 9 | use XML::TreeBuilder; |
6 | 10 |
|
7 | 11 | foreach my $file_name (@ARGV) { |
8 | 12 | my $tree = XML::TreeBuilder->new({'NoExpand' => 0, 'ErrorContext' => 0}); |
9 | 13 | $tree->parse_file($file_name, ProtocolEncoding => 'UTF-8'); |
10 | 14 | foreach my $string ($tree->find_by_tag_name('message')) { |
11 | 15 | 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); |
18 | 24 | } |
19 | 25 | } |
20 | 26 | } |
| 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