X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=build%2Fi18n-update.pl;h=c82b4fe3dd610b53dcd5160400faa8fd1d915c3e;hp=16b82e8dddc126d4223f251dfac42bd2794605f8;hb=ec6a1d6d4d05f956f47b889161178f6a4abf90cc;hpb=0b0df324bfdcf4bb9870a8edd82567f4091d6ff1 diff --git a/build/i18n-update.pl b/build/i18n-update.pl index 16b82e8dd..c82b4fe3d 100755 --- a/build/i18n-update.pl +++ b/build/i18n-update.pl @@ -1,11 +1,11 @@ #!/usr/bin/perl -@ARGV >= 1 || die "Usage: $0 []\n"; +@ARGV <= 2 || die "Usage: $0 [] []\n"; my $source = shift @ARGV; my $pattern = shift @ARGV || '*.po'; -sub fixup_header_order +sub read_header { my $file = shift || return; local $/; @@ -14,26 +14,70 @@ sub fixup_header_order my $data = readline P; close P; - $data =~ s/("Language-Team: .*?\\n"\n)(.+?)("Language: .*?\\n"\n)/$1$3$2/s; + $data =~ / + ^ ( + msgid \s "" \n + msgstr \s "" \n + (?: " [^\n]+ " \n )+ + \n ) + /mx; + + return $1; +} + +sub write_header +{ + my $file = shift || return; + my $head = shift || return; + local $/; + + open P, "< $file" || die "open(): $!"; + my $data = readline P; + close P; + + $data =~ s/ + ^ ( + msgid \s "" \n + msgstr \s "" \n + (?: " [^\n]+ " \n )+ + \n ) + /$head/mx; open P, "> $file" || die "open(): $!"; print P $data; close P; } -if( open F, "find $source -type f -name '$pattern' |" ) +my @dirs; + +if( ! $source ) { - while( chomp( my $file = readline F ) ) + @dirs = glob("./*/*/po/"); +} +else +{ + @dirs = ( $source ); +} + +foreach my $dir (@dirs) +{ + if( open F, "find $dir -type f -name '$pattern' |" ) { - my ( $basename ) = $file =~ m{.+/([^/]+)\.po$}; - - if( -f "$source/templates/$basename.pot" ) + while( chomp( my $file = readline F ) ) { - printf "Updating %-40s", $file; - system("msgmerge", "-U", "-N", $file, "$source/templates/$basename.pot"); - fixup_header_order($file); + my ( $basename ) = $file =~ m{.+/([^/]+)\.po$}; + + if( -f "$dir/templates/$basename.pot" ) + { + my $head = read_header($file); + + printf "Updating %-40s", $file; + system("msgmerge", "-U", "-N", $file, "$dir/templates/$basename.pot"); + + write_header($file, $head); + } } - } - close F; + close F; + } }