2018-08-31 15:51:40 +02:00
|
|
|
#!/usr/bin/perl --
|
|
|
|
use XML::Parser;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Find;
|
2018-09-01 02:49:57 +02:00
|
|
|
use XML::Simple;
|
|
|
|
use Data::Dump qw(dump);
|
|
|
|
|
2019-09-29 19:40:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
sub cmd($){
|
|
|
|
print "+ ",$_[0],"\n";
|
|
|
|
my $rv=system $_[0];
|
|
|
|
if ($? == -1) {
|
|
|
|
die "failed to execute: $!\n";
|
|
|
|
}elsif ($? & 127) {
|
|
|
|
die "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
|
|
|
}else {
|
|
|
|
my $rv = $? >> 8;
|
|
|
|
$rv and die "child exited with value $rv\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# ワーキングツリーに変更がないことを確認
|
|
|
|
open(my $fh,"-|","git status --porcelain --branch")
|
|
|
|
or die "can't check git status. $!";
|
|
|
|
|
|
|
|
my @untrackedFiles;
|
|
|
|
while(<$fh>){
|
|
|
|
chomp;
|
|
|
|
if(/^\?\?\s*(\S+)/){
|
|
|
|
my $path =$1;
|
|
|
|
next if $path =~ /\.idea|_Emoji/;
|
|
|
|
push @untrackedFiles,$path
|
|
|
|
}elsif( /^##\s*(\S+?)(?:\.\.|$)/ ){
|
|
|
|
my $branch=$1;
|
|
|
|
print "# branch=$branch\n";
|
|
|
|
$branch eq 'master'
|
|
|
|
or die "current branch is not master.\n";
|
|
|
|
# }else{
|
|
|
|
# warn "working tree is not clean.\n";
|
|
|
|
# cmd "git status";
|
|
|
|
# exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close($fh)
|
|
|
|
or die "can't check git status. $!";
|
|
|
|
|
|
|
|
@untrackedFiles and die "forgot git add?\n",map{ "- $_\n"} @untrackedFiles;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-01 02:49:57 +02:00
|
|
|
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
|
|
|
}
|
2018-09-01 02:49:57 +02:00
|
|
|
my $data = $xml->XMLin($file);
|
2018-09-09 02:11:31 +02:00
|
|
|
if( not $data->{string} or ($data->{string}{content} and not ref $data->{string}{content} )){
|
2018-10-25 01:32:38 +02:00
|
|
|
warn "!! please make at least 2 string entries in $file\n";
|
|
|
|
next;
|
2018-09-09 02:11:31 +02:00
|
|
|
}
|
2018-09-01 02:49:57 +02:00
|
|
|
|
2018-08-31 15:51:40 +02:00
|
|
|
my %names;
|
2018-09-01 02:49:57 +02:00
|
|
|
while(my($name,$o)=each %{$data->{string}}){
|
2018-09-27 17:34:23 +02:00
|
|
|
if(not $o->{content}){
|
2018-09-27 17:26:01 +02:00
|
|
|
warn "$lang : $name : missing content in ",dump($o),"\n";
|
2018-09-27 17:34:23 +02:00
|
|
|
}else{
|
|
|
|
$names{$name}= $o->{content};
|
2018-09-27 17:26:01 +02:00
|
|
|
}
|
2018-09-01 02:49:57 +02:00
|
|
|
}
|
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";
|
2018-09-01 02:49:57 +02:00
|
|
|
my %params;
|
|
|
|
while(my($name,$value)=each %$master){
|
2018-09-01 03:11:29 +02:00
|
|
|
my @params = $value =~ /(%\d+\$[\d\.]*[sdxf])/g;
|
2018-09-01 02:49:57 +02:00
|
|
|
$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){
|
2018-09-27 17:26:01 +02:00
|
|
|
|
2018-08-31 15:51:40 +02:00
|
|
|
$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;
|
2018-09-01 02:49:57 +02:00
|
|
|
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;
|
2018-09-01 02:49:57 +02:00
|
|
|
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-09-05 16:33:04 +02:00
|
|
|
|
|
|
|
# エスケープされていないシングルクォートがあればエラー
|
|
|
|
if( $value =~ m/(?<!\\)['"]/ ){
|
|
|
|
print "!! ($lang)$name : containg single or double quote without escape.\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-08-31 16:18:25 +02:00
|
|
|
|
2018-09-01 03:11:29 +02:00
|
|
|
$hasError and die "please fix error(s).\n";
|
|
|
|
|
2018-09-01 02:49:57 +02:00
|
|
|
# Weblateの未マージのブランチがあるか調べる
|
|
|
|
system qq(git fetch weblate -q);
|
2018-08-31 16:18:25 +02:00
|
|
|
my @list = `git branch -a --no-merged`;
|
|
|
|
for(@list){
|
|
|
|
print "# Unmerged branch: $_\n";
|
|
|
|
}
|
|
|
|
|
2018-08-31 15:51:40 +02:00
|
|
|
exit 0;
|