#!/usr/bin/env perl
use
lib
"$FindBin::Bin/../thirdparty/perl5"
;
my
%idStr
;
my
$root
=
shift
@ARGV
;
my
$podir
=
shift
@ARGV
;
die
"$0 <lib-directory> <po-share>\n"
unless
-d
$root
and -d
$podir
;
find ({
bydepth
=> 1,
follow
=> 1,
no_chdir
=> 1,
wanted
=>
sub
{
return
if
not ( /\.pm$/ and -f);
my
$pm
= PPI::Document->new(
$_
);
$pm
->index_locations;
for
my
$el
(@{
$pm
->find(
'PPI::Token::Word'
)}){
next
if
not
$el
->content eq
'trm'
;
my
$location
=
$el
->location;
my
$next
=
$el
->snext_sibling;
next
if
not
$next
->isa(
'PPI::Structure::List'
);
my
$id
= decode(
'utf8'
,
$next
->find_first(
'PPI::Token::Quote'
)->string);
my
$filename
=
$_
;
$filename
=~ s{^
$root
/?}{};
push
@{
$idStr
{
$id
}},
$filename
.
':'
.
$el
->line_number;
}
}
},
$root
);
for
my
$poFile
(
glob
$podir
.
"/*.po"
){
my
$po
= Locale::PO->load_file_ashash(
$poFile
,
'utf8'
);
for
my
$id
(
keys
%idStr
){
my
$poKey
= Locale::PO->quote(
$id
);
next
if
$po
->{
$poKey
};
my
$item
=
$po
->{
$poKey
} //= new Locale::PO(
-msgid
=>
$id
,
-msgstr
=>
''
);
$item
->reference(
join
(
"\n"
, @{
$idStr
{
$id
}}));
}
for
my
$poKey
(
keys
%$po
){
next
if
$poKey
eq
'""'
;
my
$id
= Locale::PO->dequote(
$poKey
);
if
(not
$idStr
{
$id
}) {
my
$ref
=
$po
->{
$poKey
}->reference;
delete
$po
->{
$poKey
}
unless
$ref
=~ m/\.cfg/;
}
}
$po
->{
'""'
} //= new Locale::PO(
-msgid
=>
''
,
-msgstr
=>
"Project-Id-Version: PACKAGE VERSION\\n"
.
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n"
.
"Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n"
.
"Language-Team: LANGUAGE <LL\@li.org>\\n"
.
"MIME-Version: 1.0\\n"
.
"Content-Type: text/plain; charset=utf-8\\n"
.
"Content-Transfer-Encoding: 8bit\\n"
);
Locale::PO->save_file_fromhash(
$poFile
,
$po
,
'utf8'
);
}