5 use Text::Balanced qw(extract_bracketed extract_delimited extract_tagged);
7 @ARGV >= 1 || die "Usage: $0 <source direcory>\n";
35 if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' ')' |" )
37 while( defined( my $file = readline F ) )
41 if( open S, "< $file" )
50 while( $text =~ s/ ^ .*? (?:translate|translatef|i18n|_) [\n\s]* \( /(/sgx )
52 ( my $code, $text ) = extract_bracketed($text, q{('")});
54 $code =~ s/^\([\n\s]*//;
55 $code =~ s/[\n\s]*\)$//;
60 if( $code =~ /^['"]/ )
64 ( $sub, $code ) = extract_delimited($code, q{'"}, q{\s*(?:\.\.\s*)?});
68 $res .= substr $sub, 1, length($sub) - 2;
72 elsif( $code =~ /^(\[=*\[)/ )
74 my $stag = quotemeta $1;
78 ( $res ) = extract_tagged($code, $stag, $etag);
84 $res = dec_lua_str($res);
85 $stringtable{$res}++ if $res;
91 while( $text =~ s/ ^ .*? <% -? [:_] /<%/sgx )
93 ( my $code, $text ) = extract_tagged($text, '<%', '%>');
97 $code = dec_tpl_str(substr $code, 2, length($code) - 4);
98 $stringtable{$code}++;
108 if( open C, "| msgcat -" )
110 printf C "msgid \"\"\nmsgstr \"Content-Type: text/plain; charset=UTF-8\"\n\n";
112 foreach my $key ( sort keys %stringtable )
117 printf C "msgid \"%s\"\nmsgstr \"\"\n\n", $key;