5 use Text::Balanced qw(extract_codeblock);
7 @ARGV == 1 || die "Usage: $0 <source direcory>\n";
15 if( $code =~ s/^<%:-?\s*(.+)\s*%>/$1/s )
17 my ( $key, @text ) = split /[\n\s]+/, $code;
22 elsif( $code =~ s/^\(\s*(.+)\s*\)/$1/s )
24 if( $code =~ /^(?:"(\w+)"|'(\w+)')\s*,\s*(?:"(.+?)"|'(.+?)')/s )
30 elsif( $code =~ /^(?:"(\w+)"|'(\w+)')/ )
52 if( open F, "find $ARGV[0] -type f -name '*.htm' -or -name '*.lua' |" )
54 while( defined( my $file = readline F ) )
58 if( open S, "< $file" )
61 $text .= $_ foreach( readline S );
67 (?: translate f? | i18n )
76 ( $code, $text ) = extract_codeblock( $text, '', '^', '()' );
78 ( $code, $text ) = extract_codeblock( $text, '', '^', '<>' );
83 $text =~ s/(#[^\n]*)%>/$1\n%>/;
84 ( $code, $text ) = extract_codeblock( $text, '<>', '^' );
90 my ( $k, $v ) = _parse( $code );
91 if( $k && defined($v) )
95 printf "#. %s\n", $v || $k;
98 printf "msgid \"%s\"\nmsgstr \"%s\"\n\n",