[Po4a-commits] "po4a po4a,1.98,1.99"
Denis Barbier
barbier-guest at alioth.debian.org
Sat Apr 17 08:52:29 UTC 2010
Update of /cvsroot/po4a/po4a
In directory alioth:/tmp/cvs-serv10356
Modified Files:
po4a
Log Message:
New '--build-only <file>' option
Translate only the specified file. It may be useful to speed up
processing if configuration file contains a lot of files. Note that this
option reorders entries in PO and POT files, it should be used with care.
This option can be used multiple times.
Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- po4a 30 Jan 2010 09:38:34 -0000 1.98
+++ po4a 17 Apr 2010 08:52:26 -0000 1.99
@@ -386,6 +386,13 @@
Remove the .po~ backup files (implies --no-backups).
+=item --build-only I<translated-file>
+
+Translate only the specified file. It may be useful to speed up
+processing if configuration file contains a lot of files. Note that this
+option reorders entries in PO and POT files, it should be used with care.
+This option can be used multiple times.
+
=item --variable I<var>=I<value>
Define a variable that will be expanded in the po4a configuration file.
@@ -532,6 +539,7 @@
"addchar" => "",
"options" => {"verbose" => 0, "debug" => 0},
"variables" => {},
+ "partial" => [],
"copyright-holder"=> undef,
"msgid-bugs-address"=> undef,
"package-name" => undef,
@@ -557,6 +565,7 @@
'keep|k=s' => \$opts{"threshold"},
'no-translations' => \$opts{"no-translations"},
'rm-translations' => \$opts{"rm-translations"},
+ 'build-only=s' => \@{$opts{"partial"}},
'no-backups' => \$opts{"no-backups"},
'rm-backups' => \$opts{"rm-backups"},
'version|V' => \&show_version,
@@ -705,6 +714,7 @@
my (%po_filename); # po_files: '$lang'=>'$path'
my (%document); # '$master'=> {'format'=>'$format'; '$lang'=>'$path'; 'add_$lang'=>('$path','$path') }
my $doc_count = 0;
+my %partial = ( 'skip' => [], 'master' => {}, 'files' => {}, 'lang' => {} );
open CONFIG,"<","$config_file" or die wrap_msg(gettext("Can't open %s: %s"), $config_file, $!);
my ($line,$nb) = ("",0);
while (<CONFIG>) {
@@ -823,6 +833,19 @@
die wrap_ref_mod("$config_file:$nb", "",
gettext("The '%s' master file does not exist."), $main);
}
+ if (scalar @{$po4a_opts{"partial"}}) {
+ my $found = 0;
+ foreach my $file (@{$po4a_opts{"partial"}}) {
+ if ($args =~ m/(\S+):\Q$file\E\b/) {
+ $partial{'lang'}{$1} = 1;
+ $partial{'master'}{$main} = 1;
+ $partial{'files'}{$file} = 1;
+ $found = 1;
+ last;
+ }
+ }
+ push (@{$partial{'skip'}}, $main) unless $found;
+ }
$document{$main}{'format'} = $1;
$document{$main}{'pos'} = $doc_count;
$doc_count++;
@@ -979,6 +1002,10 @@
if ($pot_filename =~ m/\$master/) {
print wrap_msg(gettext("Split mode, creating a temporary POT")."\n")
if $po4a_opts{"verbose"};
+ if (scalar @{$po4a_opts{"partial"}}) {
+ print wrap_msg(gettext("Disabling --build-only option, it is not supported in split mode")."\n");
+ $po4a_opts{"partial"} = [];
+ }
foreach my $master (keys %document) {
next if ($master eq '');
my $m = basename $master;
@@ -990,6 +1017,18 @@
$update_pot_file = 1;
$po4a_opts{"split"} = 1;
} else {
+ if (scalar @{$po4a_opts{"partial"}}) {
+ # Skip documents not specified, strings are read directly from POT file
+ foreach my $master (keys %document) {
+ next unless length $master;
+ delete $document{$master} unless exists $partial{'master'}{$master};
+ }
+ # Do not touch PO files if no file is processed for this language
+ foreach my $lang (keys %po_filename) {
+ delete $po_filename{$lang} unless exists $partial{'lang'}{$lang};
+ }
+ }
+
chdir $po4a_opts{"srcdir"}
if (defined $po4a_opts{"srcdir"});
if (-e $pot_filename) {
@@ -1043,6 +1082,18 @@
chdir $po4a_opts{"srcdir"}
if (defined $po4a_opts{"srcdir"});
my $potfile=Locale::Po4a::Po->new(\%Po_opts);
+if (scalar @{$po4a_opts{"partial"}} and -e $pot_filename) {
+ print wrap_msg(gettext("Partial update, reading %s first")." ", $pot_filename)
+ if ($po4a_opts{"verbose"});
+ $potfile->read($pot_filename);
+ $potfile = $potfile->filter("(reference=\"(^| )(".join("|", @{$partial{'skip'}})."):\")");
+ # FIXME: We have to modify $potfile internals to remove references, there
+ # should be a $potfile->remove_references($foo) method instead.
+ my $re = "(".join('|', keys %{$partial{'master'}})."):\\d+\\s*";
+ foreach my $msgid (keys %{$potfile->{po}}) {
+ $potfile->{po}{$msgid}{'reference'} =~ s/$re//go;
+ }
+}
chdir $po4a_opts{"calldir"}
if (defined $po4a_opts{"srcdir"});
if ($update_pot_file) {
@@ -1087,11 +1138,11 @@
$!);
$potfile->write($pot_filename);
} else {
- if ($po4a_opts{"force"}) {
- $potfile->write($pot_filename);
- } else {
- $potfile->write_if_needed($pot_filename);
- }
+ if ($po4a_opts{"force"}) {
+ $potfile->write($pot_filename);
+ } else {
+ $potfile->write_if_needed($pot_filename);
+ }
}
chdir $po4a_opts{"calldir"}
if (defined $po4a_opts{"srcdir"});
@@ -1305,6 +1356,9 @@
$document{$b}{'pos'} } keys %document) {
next if ($master eq '');
next unless defined $document{$master}{$lang};
+ if (scalar @{$po4a_opts{"partial"}}) {
+ next unless defined $partial{'files'}{$document{$master}{$lang}};
+ }
unless ($po4a_opts{"force"}) {
chdir $po4a_opts{"destdir"}
More information about the Po4a-commits
mailing list