build: i18n-scan.pl: properly handle bracket-quoted strings
Fixes: #2738 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
17d6746989
commit
4bbc033a96
1 changed files with 52 additions and 40 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Text::Balanced qw(extract_bracketed extract_delimited extract_tagged);
|
use Text::Balanced qw(extract_tagged gen_delimited_pat);
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
|
||||||
POSIX::setlocale(POSIX::LC_ALL, "C");
|
POSIX::setlocale(POSIX::LC_ALL, "C");
|
||||||
|
@ -15,10 +15,10 @@ my %stringtable;
|
||||||
sub dec_lua_str
|
sub dec_lua_str
|
||||||
{
|
{
|
||||||
my $s = shift;
|
my $s = shift;
|
||||||
$s =~ s/[\s\n]+/ /g;
|
|
||||||
$s =~ s/\\n/\n/g;
|
$s =~ s/\\n/\n/g;
|
||||||
$s =~ s/\\t/\t/g;
|
$s =~ s/\\t/\t/g;
|
||||||
$s =~ s/\\(.)/$1/g;
|
$s =~ s/\\(.)/$1/sg;
|
||||||
|
$s =~ s/[\s\n]+/ /g;
|
||||||
$s =~ s/^ //;
|
$s =~ s/^ //;
|
||||||
$s =~ s/ $//;
|
$s =~ s/ $//;
|
||||||
return $s;
|
return $s;
|
||||||
|
@ -35,7 +35,6 @@ sub dec_tpl_str
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' -o -name '*.js' ')' | sort |" )
|
if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' -o -name '*.js' ')' | sort |" )
|
||||||
{
|
{
|
||||||
while( defined( my $file = readline F ) )
|
while( defined( my $file = readline F ) )
|
||||||
|
@ -48,63 +47,76 @@ if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' -o -name '*.j
|
||||||
my $raw = <S>;
|
my $raw = <S>;
|
||||||
close S;
|
close S;
|
||||||
|
|
||||||
|
|
||||||
my $text = $raw;
|
my $text = $raw;
|
||||||
my $line = 1;
|
my $line = 1;
|
||||||
|
|
||||||
while( $text =~ s/ ^ (.*?) (?:translate|translatef|i18n|_) ([\n\s]*) \( /(/sgx )
|
while ($text =~ s/ ^ (.*?) (?:translate|translatef|i18n|_) ([\n\s]*) \( //sgx)
|
||||||
{
|
{
|
||||||
my ($prefix, $suffix) = ($1, $2);
|
my ($prefix, $suffix) = ($1, $2);
|
||||||
|
my $code;
|
||||||
( my $code, $text ) = extract_bracketed($text, q{('")});
|
my $res = "";
|
||||||
|
my $sub = "";
|
||||||
|
|
||||||
$line += () = $prefix =~ /\n/g;
|
$line += () = $prefix =~ /\n/g;
|
||||||
|
|
||||||
my $position = "$file:$line";
|
my $position = "$file:$line";
|
||||||
|
|
||||||
$line += () = $suffix =~ /\n/g;
|
$line += () = $suffix =~ /\n/g;
|
||||||
$line += () = $code =~ /\n/g;
|
|
||||||
|
|
||||||
$code =~ s/\\\n/ /g;
|
while (defined $sub)
|
||||||
$code =~ s/^\([\n\s]*//;
|
|
||||||
$code =~ s/[\n\s]*\)$//;
|
|
||||||
|
|
||||||
my $res = "";
|
|
||||||
my $sub = "";
|
|
||||||
|
|
||||||
if( $code =~ /^['"]/ )
|
|
||||||
{
|
{
|
||||||
while( defined $sub )
|
undef $sub;
|
||||||
{
|
|
||||||
( $sub, $code ) = extract_delimited($code, q{'"}, q{\s*(?:\.\.\s*)?});
|
|
||||||
|
|
||||||
if( defined $sub && length($sub) > 2 )
|
if ($text =~ /^ ([\n\s]*(?:\.\.[\n\s]*)?) (\[=*\[) /sx)
|
||||||
{
|
{
|
||||||
$res .= substr $sub, 1, length($sub) - 2;
|
my $ws = $1;
|
||||||
|
my $stag = quotemeta $2;
|
||||||
|
(my $etag = $stag) =~ y/[/]/;
|
||||||
|
|
||||||
|
($sub, $text) = extract_tagged($text, $stag, $etag, q{\s*(?:\.\.\s*)?});
|
||||||
|
|
||||||
|
$line += () = $ws =~ /\n/g;
|
||||||
|
|
||||||
|
if (defined($sub) && length($sub)) {
|
||||||
|
$line += () = $sub =~ /\n/g;
|
||||||
|
|
||||||
|
$sub =~ s/^$stag//;
|
||||||
|
$sub =~ s/$etag$//;
|
||||||
|
$res .= $sub;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
elsif ($text =~ /^ ([\n\s]*(?:\.\.[\n\s]*)?) (['"]) /sx)
|
||||||
|
{
|
||||||
|
my $ws = $1;
|
||||||
|
my $quote = $2;
|
||||||
|
my $re = gen_delimited_pat($quote, '\\');
|
||||||
|
|
||||||
|
if ($text =~ m/\G\s*(?:\.\.\s*)?($re)/gcs)
|
||||||
{
|
{
|
||||||
undef $sub;
|
$sub = $1;
|
||||||
|
$text = substr $text, pos $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
$line += () = $ws =~ /\n/g;
|
||||||
|
|
||||||
|
if (defined($sub) && length($sub)) {
|
||||||
|
$line += () = $sub =~ /\n/g;
|
||||||
|
|
||||||
|
$sub =~ s/^$quote//;
|
||||||
|
$sub =~ s/$quote$//;
|
||||||
|
$res .= $sub;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif( $code =~ /^(\[=*\[)/ )
|
|
||||||
|
if (defined($res))
|
||||||
{
|
{
|
||||||
my $stag = quotemeta $1;
|
$res = dec_lua_str($res);
|
||||||
my $etag = $stag;
|
|
||||||
$etag =~ s/\[/]/g;
|
|
||||||
|
|
||||||
( $res ) = extract_tagged($code, $stag, $etag);
|
if ($res) {
|
||||||
|
$stringtable{$res} ||= [ ];
|
||||||
$res =~ s/^$stag//;
|
push @{$stringtable{$res}}, $position;
|
||||||
$res =~ s/$etag$//;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$res = dec_lua_str($res);
|
|
||||||
|
|
||||||
if ($res) {
|
|
||||||
$stringtable{$res} ||= [ ];
|
|
||||||
push @{$stringtable{$res}}, $position;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue