diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-06-13 09:40:43 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2014-06-13 09:40:43 +0000 |
commit | 91ac51d693bb9480a9747b969947546b0d8f6470 (patch) | |
tree | f09be627afa54d9a42529dd447352a35ea36731f /build | |
parent | d733688ce5633f5c5220181a01453d2b56bd17a3 (diff) |
build: preserve original .po header when updating from templates to reduce diff noise
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'build')
-rwxr-xr-x | build/i18n-update.pl | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/build/i18n-update.pl b/build/i18n-update.pl index 16b82e8dd..4106c6da4 100755 --- a/build/i18n-update.pl +++ b/build/i18n-update.pl @@ -5,7 +5,7 @@ my $source = shift @ARGV; my $pattern = shift @ARGV || '*.po'; -sub fixup_header_order +sub read_header { my $file = shift || return; local $/; @@ -14,7 +14,34 @@ 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; @@ -29,9 +56,12 @@ if( open F, "find $source -type f -name '$pattern' |" ) if( -f "$source/templates/$basename.pot" ) { + my $head = read_header($file); + printf "Updating %-40s", $file; system("msgmerge", "-U", "-N", $file, "$source/templates/$basename.pot"); - fixup_header_order($file); + + write_header($file, $head); } } |