mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Check arguments of translation strings
Make sure the arguments of placeholders agree Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
15028fd299
commit
43b1a73022
1 changed files with 27 additions and 7 deletions
|
@ -1,7 +1,11 @@
|
||||||
#!/usr/bin/perl -CS
|
#!/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 strict;
|
||||||
use utf8;
|
use utf8::all;
|
||||||
use XML::TreeBuilder;
|
use XML::TreeBuilder;
|
||||||
|
|
||||||
foreach my $file_name (@ARGV) {
|
foreach my $file_name (@ARGV) {
|
||||||
|
@ -9,12 +13,28 @@ foreach my $file_name (@ARGV) {
|
||||||
$tree->parse_file($file_name, ProtocolEncoding => 'UTF-8');
|
$tree->parse_file($file_name, ProtocolEncoding => 'UTF-8');
|
||||||
foreach my $string ($tree->find_by_tag_name('message')) {
|
foreach my $string ($tree->find_by_tag_name('message')) {
|
||||||
my $source = $string->find_by_tag_name('source')->as_text;
|
my $source = $string->find_by_tag_name('source')->as_text;
|
||||||
my $translation = $string->find_by_tag_name('translation')->as_text;
|
my $translation = $string->find_by_tag_name('translation');
|
||||||
next unless $translation =~ /\S/;
|
if ($translation->find_by_tag_name('numerusform')) {
|
||||||
my @source_args = ($source =~ /\%([^\s\-\(\)])/g);
|
my @all = $translation->find_by_tag_name('numerusform');
|
||||||
my @translation_args = ($translation =~ /\%([^\s\-\(\)])/g);
|
foreach my $transstring(@all) {
|
||||||
if (scalar(@source_args) != scalar(@translation_args)) {
|
&compare($file_name, $source, $transstring->as_text);
|
||||||
print "$file_name:\n$source\n->\n$translation\n\n";
|
}
|
||||||
|
} 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue