diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-14 19:44:04 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-14 19:44:04 +0000 |
commit | 6202881b5663f23095a3fed2f531899cdae4df53 (patch) | |
tree | 1bb3bd400c5a6b2bbcaf00dedee96d92a991fc06 /build | |
parent | 3de89c4f9f9ac46dc79f415aa01436ebf9a9b81c (diff) |
build: add lua-po conversation script
Diffstat (limited to 'build')
-rwxr-xr-x | build/i18n-lua2po.pl | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/build/i18n-lua2po.pl b/build/i18n-lua2po.pl new file mode 100755 index 0000000000..262b427f2b --- /dev/null +++ b/build/i18n-lua2po.pl @@ -0,0 +1,113 @@ +#!/usr/bin/perl + +@ARGV == 3 || 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 ) +{ + system('mkdir', '-p', $target_dir); +} + + +my %target_strings; + + +if( 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; + $target_strings{$basename}{$k} = $v; + } + } + + close L; + } + } + + close F; +} + + +if( open F, "find . -path '*/luasrc/i18n/*' -name '*.$master_lang.lua' |" ) +{ + while( chomp( my $file = readline F ) ) + { + if( open L, "< $file" ) + { + my ( $basename ) = $file =~ m{.+/([^/]+)\.\w+\.lua$}; + + if( open T, "> $target_dir/$basename.$target_lang.po" ) + { + printf "Generating %-40s ", + "$target_dir/$basename.$target_lang.po"; + + printf T "# %s.%s.po\n# generated from %s\n\nmsgid \"\"\n" . + "msgstr \"Content-Type: text/plain; charset=UTF-8\"\n\n", + $basename, $target_lang, $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; + 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} : $v; + } + } + + close T; + + print "done\n"; + } + + close L; + } + } + + close F; +} |