5 use Text::Balanced qw(extract_bracketed extract_delimited extract_tagged);
7 @ARGV >= 1 || die "Usage: $0 <source direcory>\n";
36 if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' ')' |" )
38 while( defined( my $file = readline F ) )
42 if( open S, "< $file" )
51 while( $text =~ s/ ^ .*? (?:translate|translatef|i18n|_) [\n\s]* \( /(/sgx )
53 ( my $code, $text ) = extract_bracketed($text, q{('")});
56 $code =~ s/^\([\n\s]*//;
57 $code =~ s/[\n\s]*\)$//;
62 if( $code =~ /^['"]/ )
66 ( $sub, $code ) = extract_delimited($code, q{'"}, q{\s*(?:\.\.\s*)?});
68 if( defined $sub && length($sub) > 2 )
70 $res .= substr $sub, 1, length($sub) - 2;
78 elsif( $code =~ /^(\[=*\[)/ )
80 my $stag = quotemeta $1;
84 ( $res ) = extract_tagged($code, $stag, $etag);
90 $res = dec_lua_str($res);
91 $stringtable{$res}++ if $res;
97 while( $text =~ s/ ^ .*? <% -? [:_] /<%/sgx )
99 ( my $code, $text ) = extract_tagged($text, '<%', '%>');
103 $code = dec_tpl_str(substr $code, 2, length($code) - 4);
104 $stringtable{$code}++;
114 if( open C, "| msgcat -" )
116 printf C "msgid \"\"\nmsgstr \"Content-Type: text/plain; charset=UTF-8\"\n\n";
118 foreach my $key ( sort keys %stringtable )
123 printf C "msgid \"%s\"\nmsgstr \"\"\n\n", $key;