From: Jo-Philipp Wich Date: Sat, 9 May 2009 02:46:39 +0000 (+0000) Subject: build: add script to extract i18n tags from templates X-Git-Tag: 0.9.0~477 X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=b75a258aecab4f863446e078b10f10ad4ddbfcab build: add script to extract i18n tags from templates --- diff --git a/build/i18n-html2lua.pl b/build/i18n-html2lua.pl new file mode 100755 index 000000000..c6b893eee --- /dev/null +++ b/build/i18n-html2lua.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +@ARGV || die "Usage: $0 template1.htm [... templateN.htm]\n"; + + +my %tags; + +foreach my $file ( @ARGV ) +{ + if( open F, "< $file" ) + { + local $/ = undef; + + my $data = ; + + while( $data =~ m/ <%: -? (\w+) (.*?) %> /sgx ) + { + my ( $key, $val ) = ( $1, $2 ); + + if( $key && $val ) + { + $val =~ s/\s+/ /sg; + $val =~ s/^\s+//; + $val =~ s/\s+$//; + + $tags{$key} = $val; + } + else + { + $tags{$key} ||= ''; + } + } + + close F; + } +} + +foreach my $key ( sort keys %tags ) +{ + if( $val =~ /'/ ) + { + printf "%s = [[%s]]\n", $key, $tags{$key}; + } + else + { + printf "%s = '%s'\n", $key, $tags{$key}; + } +}