1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2024-12-27 17:32:54 +01:00
SubwayTooter-Android-App/checkMissingTranslation.pl

97 lines
2.2 KiB
Perl
Raw Normal View History

2018-08-31 15:51:40 +02:00
#!/usr/bin/perl --
use XML::Parser;
use strict;
use warnings;
use File::Find;
use XML::Simple;
use Data::Dump qw(dump);
my $xml = XML::Simple->new;
2018-08-31 15:51:40 +02:00
2018-08-31 15:54:12 +02:00
my $master_name = "_master";
2018-08-31 15:51:40 +02:00
my @files;
find(sub{
return if not -f $_;
($_ eq "strings.xml") and push @files,$File::Find::name;
},"app/src/main/res/");
@files or die "missing string files.\n";
my %langs;
for my $file(@files){
my $lang;
if( $file =~ m|values-([^/]+)| ){
$lang = $1;
}else{
2018-08-31 15:54:12 +02:00
$lang=$master_name;
2018-08-31 15:51:40 +02:00
}
my $data = $xml->XMLin($file);
#print dump($data);
#exit;
2018-08-31 15:51:40 +02:00
my %names;
while(my($name,$o)=each %{$data->{string}}){
$names{$name}=$o->{content};
}
2018-08-31 15:51:40 +02:00
$langs{ $lang } = \%names;
}
2018-09-01 03:11:29 +02:00
my $hasError = 0;
2018-08-31 15:54:12 +02:00
my $master = $langs{ $master_name };
2018-08-31 15:51:40 +02:00
$master or die "missing master languages.\n";
my %params;
while(my($name,$value)=each %$master){
2018-09-01 03:11:29 +02:00
my @params = $value =~ /(%\d+\$[\d\.]*[sdxf])/g;
$params{$name} = join ',', sort @params;
}
2018-08-31 15:51:40 +02:00
my %missing;
my %allNames;
2018-08-31 15:54:12 +02:00
for my $lang ( sort keys %langs ){
my $names = $langs{$lang};
2018-08-31 15:51:40 +02:00
while(my($name,$value)=each %$names){
$allNames{$name}=1;
if(not $master->{$name} ){
$missing{$name} =1;
}
2018-09-01 03:11:29 +02:00
my @params = $value =~ /(%\d+\$[\d\.]*[sdxf])/g;
my $params = join ',', sort @params;
my $master_params = $params{$name} // '';
if( $params ne $master_params){
2018-09-01 03:11:29 +02:00
$hasError =1;
print "!! ($lang)$name : parameter mismatch. master=$master_params, found=$params\n";
}
2018-09-01 03:11:29 +02:00
# 残りの部分に%が登場したらエラー
my $sv = $value;
$sv =~ s/(%\d+\$[\d\.]*[sdxf])//g;
if( $sv =~ /%/ && not $sv=~/:%/ ){
$hasError =1;
print "!! ($lang)$name : broken param: $sv // $value\n";
}
2018-08-31 15:51:40 +02:00
}
my $nameCount = 0+ keys %$names;
print "($lang)string resource count=$nameCount\n";
}
my @missing = sort keys %missing;
@missing and die "missing string resources in master language: ",join(', ',@missing),"\n";
my $nameCount = 0+ keys %allNames;
print "(total)string resource count=$nameCount\n";
2018-09-01 03:11:29 +02:00
$hasError and die "please fix error(s).\n";
# Weblateの未マージのブランチがあるか調べる
system qq(git fetch weblate -q);
my @list = `git branch -a --no-merged`;
for(@list){
print "# Unmerged branch: $_\n";
}
2018-08-31 15:51:40 +02:00
exit 0;