mirror of
https://github.com/openwrt/luci.git
synced 2025-12-21 19:14:34 +04:00
build: preserve original .po header when updating from templates to reduce diff noise
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
my $source = shift @ARGV;
|
my $source = shift @ARGV;
|
||||||
my $pattern = shift @ARGV || '*.po';
|
my $pattern = shift @ARGV || '*.po';
|
||||||
|
|
||||||
sub fixup_header_order
|
sub read_header
|
||||||
{
|
{
|
||||||
my $file = shift || return;
|
my $file = shift || return;
|
||||||
local $/;
|
local $/;
|
||||||
@@ -14,7 +14,34 @@ sub fixup_header_order
|
|||||||
my $data = readline P;
|
my $data = readline P;
|
||||||
close 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(): $!";
|
open P, "> $file" || die "open(): $!";
|
||||||
print P $data;
|
print P $data;
|
||||||
@@ -29,9 +56,12 @@ if( open F, "find $source -type f -name '$pattern' |" )
|
|||||||
|
|
||||||
if( -f "$source/templates/$basename.pot" )
|
if( -f "$source/templates/$basename.pot" )
|
||||||
{
|
{
|
||||||
|
my $head = read_header($file);
|
||||||
|
|
||||||
printf "Updating %-40s", $file;
|
printf "Updating %-40s", $file;
|
||||||
system("msgmerge", "-U", "-N", $file, "$source/templates/$basename.pot");
|
system("msgmerge", "-U", "-N", $file, "$source/templates/$basename.pot");
|
||||||
fixup_header_order($file);
|
|
||||||
|
write_header($file, $head);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user