build: readd both po2lua and lua2po helper scripts...
This commit is contained in:
parent
c78c91b9a9
commit
9714667b2a
2 changed files with 147 additions and 0 deletions
120
build/i18n-lua2po.pl
Executable file
120
build/i18n-lua2po.pl
Executable file
|
@ -0,0 +1,120 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
@ARGV >= 2 || die "Usage: $0 <source-dir> <dest-dir> [<target-language>]\n";
|
||||||
|
|
||||||
|
my $source_dir = shift @ARGV;
|
||||||
|
my $target_dir = shift @ARGV;
|
||||||
|
my $target_lang = shift @ARGV;
|
||||||
|
my $master_lang = "en";
|
||||||
|
|
||||||
|
|
||||||
|
if( ! -d "$target_dir/" . ( $target_lang || 'templates' ) )
|
||||||
|
{
|
||||||
|
system('mkdir', '-p', "$target_dir/" . ( $target_lang || 'templates' ));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my %target_strings;
|
||||||
|
|
||||||
|
if( $target_lang && open F, "find $source_dir -path '*/luasrc/i18n/*' -name '*.$target_lang.lua' |" )
|
||||||
|
{
|
||||||
|
while( chomp( my $file = readline F ) )
|
||||||
|
{
|
||||||
|
if( open L, "< $file" )
|
||||||
|
{
|
||||||
|
my ( $basename ) = $file =~ m{.+/([^/]+)\.[\w\-]+\.lua$};
|
||||||
|
$target_strings{$basename} = { };
|
||||||
|
|
||||||
|
while( chomp( my $entry = readline L ) )
|
||||||
|
{
|
||||||
|
my ( $k, $v );
|
||||||
|
if( $entry =~ /^\s*(\w+)\s*=\s*\[\[(.+)\]\]/ )
|
||||||
|
{
|
||||||
|
( $k, $v ) = ( $1, $2 );
|
||||||
|
}
|
||||||
|
elsif( $entry =~ /^\s*(\w+)\s*=\s*'(.+)'/ )
|
||||||
|
{
|
||||||
|
( $k, $v ) = ( $1, $2 );
|
||||||
|
}
|
||||||
|
elsif( $entry =~ /^\s*(\w+)\s*=\s*"(.+)"/ )
|
||||||
|
{
|
||||||
|
( $k, $v ) = ( $1, $2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $k && $v )
|
||||||
|
{
|
||||||
|
$v =~ s/"/\\"/g;
|
||||||
|
$v =~ s/\\\\"/\\"/g;
|
||||||
|
$target_strings{$basename}{$k} = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close F;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( open F, "find . -path '*/luasrc/i18n/*' -name '*.$master_lang.lua' |" )
|
||||||
|
{
|
||||||
|
my $destfile = sprintf '%s/%s/%%s.%s',
|
||||||
|
$target_dir,
|
||||||
|
$target_lang || 'templates',
|
||||||
|
$target_lang ? 'po' : 'pot'
|
||||||
|
;
|
||||||
|
|
||||||
|
while( chomp( my $file = readline F ) )
|
||||||
|
{
|
||||||
|
if( open L, "< $file" )
|
||||||
|
{
|
||||||
|
my ( $basename ) = $file =~ m{.+/([^/]+)\.\w+\.lua$};
|
||||||
|
my $filename = sprintf $destfile, $basename;
|
||||||
|
|
||||||
|
if( open T, "> $filename" )
|
||||||
|
{
|
||||||
|
printf "Generating %-40s ", $filename;
|
||||||
|
|
||||||
|
printf T "# %s.%s\n# generated from %s\n\nmsgid \"\"\n" .
|
||||||
|
"msgstr \"Content-Type: text/plain; charset=UTF-8\"\n\n",
|
||||||
|
$basename, $target_lang ? 'po' : 'pot', $file;
|
||||||
|
|
||||||
|
while( chomp( my $entry = readline L ) )
|
||||||
|
{
|
||||||
|
my ( $k, $v );
|
||||||
|
if( $entry =~ /^\s*(\w+)\s*=\s*\[\[(.+)\]\]/ )
|
||||||
|
{
|
||||||
|
( $k, $v ) = ( $1, $2 );
|
||||||
|
}
|
||||||
|
elsif( $entry =~ /^\s*(\w+)\s*=\s*'(.+)'/ )
|
||||||
|
{
|
||||||
|
( $k, $v ) = ( $1, $2 );
|
||||||
|
}
|
||||||
|
elsif( $entry =~ /^\s*(\w+)\s*=\s*"(.+)"/ )
|
||||||
|
{
|
||||||
|
( $k, $v ) = ( $1, $2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $k && $v )
|
||||||
|
{
|
||||||
|
$v =~ s/"/\\"/g;
|
||||||
|
$v =~ s/\\\\"/\\"/g;
|
||||||
|
printf T "#: %s:%d\n#. %s\nmsgid \"%s\"\nmsgstr \"%s\"\n\n",
|
||||||
|
$file, $., $v, $k,
|
||||||
|
( $target_strings{$basename} && $target_strings{$basename}{$k} )
|
||||||
|
? $target_strings{$basename}{$k} : "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close T;
|
||||||
|
|
||||||
|
print "done\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
close L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close F;
|
||||||
|
}
|
27
build/i18n-po2lua.pl
Executable file
27
build/i18n-po2lua.pl
Executable file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
@ARGV == 2 || die "Usage: $0 <source-dir> <dest-dir>\n";
|
||||||
|
|
||||||
|
my $source_dir = shift @ARGV;
|
||||||
|
my $target_dir = shift @ARGV;
|
||||||
|
|
||||||
|
if( ! -d $target_dir )
|
||||||
|
{
|
||||||
|
system('mkdir', '-p', $target_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( open F, "find $source_dir -type f -name '*.po' |" )
|
||||||
|
{
|
||||||
|
while( chomp( my $file = readline F ) )
|
||||||
|
{
|
||||||
|
my ( $lang, $basename ) = $file =~ m{.+/(\w+)/([^/]+)\.po$};
|
||||||
|
$lang = lc $lang;
|
||||||
|
$lang =~ s/_/-/g;
|
||||||
|
|
||||||
|
printf "Generating %-40s ", "$target_dir/$basename.$lang.lmo";
|
||||||
|
system("./build/po2lmo", $file, "$target_dir/$basename.$lang.lmo");
|
||||||
|
print ( -f "$target_dir/$basename.$lang.lmo" ? "done\n" : "empty\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
close F;
|
||||||
|
}
|
Loading…
Reference in a new issue