fc516c6a04bc81fb759d8f1e69bd0a0c5fc882e2
6 use Text
::Balanced
qw(extract_tagged gen_delimited_pat);
9 POSIX
::setlocale
(POSIX
::LC_ALL
, "C");
11 @ARGV >= 1 || die "Usage: $0 <source directory>\n";
29 $s =~ s
!\\(?
:([0-9]{1,2})|(.))!
30 $1 ?
chr(int($1)) : ($rep{$2} || $2)
54 $s =~ s
!\\([\\/"bfnrt]|u([0-9a-fA-F]{4}))!
55 $2 ? chr(hex($2)) : $rep{$1}
76 if( open F, "find
@ARGV -type f
'(' -name
'*.htm' -o
-name
'*.lua' -o
-name
'*.js' ')' | sort |" )
78 while( defined( my $file = readline F ) )
82 if( open S, "< $file" )
93 while ($text =~ s/ ^ (.*?) (?:translate|translatef|i18n|_) ([\n\s]*) \( //sgx)
95 my ($prefix, $suffix) = ($1, $2);
100 $line += () = $prefix =~ /\n/g;
102 my $position = "$file:$line";
104 $line += () = $suffix =~ /\n/g;
110 if ($text =~ /^ ([\n\s]*(?:\.\.[\n\s]*)?) (\[=*\[) /sx)
113 my $stag = quotemeta $2;
114 (my $etag = $stag) =~ y/[/]/;
116 ($sub, $text) = extract_tagged($text, $stag, $etag, q{\s*(?:\.\.\s*)?});
118 $line += () = $ws =~ /\n/g;
120 if (defined($sub) && length($sub)) {
121 $line += () = $sub =~ /\n/g;
128 elsif ($text =~ /^ ([\n\s]*(?:\.\.[\n\s]*)?) (['"]) /sx)
132 my $re = gen_delimited_pat
($quote, '\\');
134 if ($text =~ m/\G\s*(?:\.\.\s*)?($re)/gcs)
137 $text = substr $text, pos $text;
140 $line += () = $ws =~ /\n/g;
142 if (defined($sub) && length($sub)) {
143 $line += () = $sub =~ /\n/g;
154 $res = dec_lua_str
($res);
157 $stringtable{$res} ||= [ ];
158 push @
{$stringtable{$res}}, $position;
167 while( $text =~ s/ ^ (.*?) <% -? [:_] /<%/sgx )
169 $line += () = $1 =~ /\n/g;
171 ( my $code, $text ) = extract_tagged
($text, '<%', '%>');
175 my $position = "$file:$line";
177 $line += () = $code =~ /\n/g;
179 $code = dec_tpl_str
(substr $code, 2, length($code) - 4);
181 $stringtable{$code} ||= [];
182 push @
{$stringtable{$code}}, $position;
191 if( open F
, "find @ARGV -type f -path '*/menu.d/*.json' | sort |" )
193 while( defined( my $file = readline F
) )
197 if( open S
, "< $file" )
208 while ($text =~ s/ ^ (.*?) "title" ([\n\s]*) : //sgx)
210 my ($prefix, $suffix) = ($1, $2);
215 $line += () = $prefix =~ /\n/g;
217 my $position = "$file:$line";
219 $line += () = $suffix =~ /\n/g;
225 if ($text =~ /^ ([\n\s]*) " /sx)
228 my $re = gen_delimited_pat
('"', '\\');
230 if ($text =~ m/\G\s*($re)/gcs)
233 $text = substr $text, pos $text;
236 $line += () = $ws =~ /\n/g;
238 if (defined($sub) && length($sub)) {
239 $line += () = $sub =~ /\n/g;
250 $res = dec_json_str
($res);
253 $stringtable{$res} ||= [ ];
254 push @
{$stringtable{$res}}, $position;
265 if( open C
, "| msgcat -" )
269 printf C
"msgid \"\"\nmsgstr \"Content-Type: text/plain; charset=UTF-8\"\n\n";
271 foreach my $key ( sort keys %stringtable )
276 map { join ':', @
$_ }
277 sort { ($a->[0] cmp $b->[0]) || ($a->[1] <=> $b->[1]) }
278 map { [ /^(.+):(\d+)$/ ] }
279 @
{$stringtable{$key}};
286 printf C
"#: %s\nmsgid \"%s\"\nmsgstr \"\"\n\n",
287 join(' ', @positions), $key;