From 44f8ee44e641c740b57c68dfd33a0d0a69b3f084 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sat, 27 May 2017 17:13:17 +0100 Subject: [PATCH] check for missing src strings too --- scripts/check-i18n.pl | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/scripts/check-i18n.pl b/scripts/check-i18n.pl index ebafa0b19c..a7e5f3c2e2 100755 --- a/scripts/check-i18n.pl +++ b/scripts/check-i18n.pl @@ -13,8 +13,30 @@ $|=1; $0 =~ /^(.*\/)/; my $i18ndir = abs_path($1."/../src/i18n/strings"); +my $srcdir = abs_path($1."/../src"); + my $en = read_i18n($i18ndir."/en_EN.json"); +my $src_strings = read_src_strings($srcdir); + +print "Checking strings in src\n"; +foreach my $s (@$src_strings) { + if (!$en->{$s}) { + if ($en->{$s . '.'}) { + printf ("%10s %24s\t%s\n", "src", "en_EN has fullstop!", "$s"); + } + else { + $s =~ /^(.*)\.?$/; + if ($en->{$1}) { + printf ("%10s %24s\t%s\n", "src", "en_EN lacks fullstop!", "$s"); + } + else { + printf ("%10s %24s\t%s\n", "src", "Translation missing!", "$s"); + } + } + } +} + opendir(DIR, $i18ndir) || die $!; my @files = readdir(DIR); closedir(DIR); @@ -65,4 +87,29 @@ sub read_i18n { close(FILE); return $map; +} + +sub read_src_strings { + my $path = shift; + + use File::Find; + use File::Slurp; + + my $strings = []; + + my @files; + find( sub { push @files, $File::Find::name if (-f $_ && /\.jsx?$/) }, $path ); + foreach my $file (@files) { + my $src = read_file($file); + while ($src =~ /_t\(\s*'(.*?[^\\])'/sg) { + my $s = $1; + $s =~ s/\\'/'/g; + push @$strings, $s; + } + while ($src =~ /_t\(\s*"(.*?[^\\])"/sg) { + push @$strings, $1; + } + } + + return $strings; } \ No newline at end of file