[Po4a-commits] "po4a po4a, 1.71, 1.72 changelog, 1.181, 1.182 NEWS,
1.18, 1.19"
Nicolas FRANCOIS
nekral-guest at alioth.debian.org
Mon Mar 26 22:40:05 CET 2007
Update of /cvsroot/po4a/po4a
In directory alioth:/tmp/cvs-serv25537
Modified Files:
po4a changelog NEWS
Log Message:
Update translations based on modification times. Use timestamp to avoid
retrying generate uncompleted translations. (can be deactivated with
--force).
Index: NEWS
===================================================================
RCS file: /cvsroot/po4a/po4a/NEWS,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- NEWS 26 Mar 2007 21:06:47 -0000 1.18
+++ NEWS 26 Mar 2007 21:40:02 -0000 1.19
@@ -26,6 +26,9 @@
po4a: Add new tag: [options] to set global options (i.e. for every
documents in the configuration file).
+ po4a: Update translations based on modification times. Use timestamp to
+ avoid retrying generate uncompleted translations.
+
===============================================================================
* Major changes in release 0.30 (2007-01-05)
Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- po4a 26 Mar 2007 21:06:47 -0000 1.71
+++ po4a 26 Mar 2007 21:40:02 -0000 1.72
@@ -239,13 +239,24 @@
=over
-If the POT file already exists, it is regenerated if a master document is
-more recent.
+If the POT file already exists, it is regenerated if a master document
+or the configuration file is more recent.
The POT file is also written in a temporary document and po4a verifies
that the changes are really needed.
+Also, a translation is regenerated only if its master document, the PO file,
+one of its addenda or the configuration file is more recent.
+To avoid trying to regenerate translations which do not pass the threshold
+test (see B<--keep>), a file with the '.po4a-stamp' extension is created.
+These stamp files are removed when po4a is called with the
+B<--rm-translations> flag or when a file is finally translated.
+
=back
+If a master document includes files, you should use the B<--force> flag
+because the modification time of these included files are not taken into
+account.
+
The PO files are always re-generated based on the POT with B<msgmerge -U>.
=item --no-translations
@@ -328,6 +339,7 @@
use File::Temp;
use File::Basename;
use File::Copy;
+use Fcntl; # sysopen flags
Locale::Po4a::Common::textdomain('po4a');
@@ -979,6 +991,25 @@
next if ($master eq '');
next unless defined $document{$master}{$lang};
+ unless ($po4a_opts{"force"}) {
+ my $stampfile = $document{$master}{$lang};
+ unless (-e $document{$master}{$lang}) {
+ $stampfile = $document{$master}{$lang}.".po4a-stamp";
+ }
+
+ my @files = ($master, $po_filename{$lang}, $config_file);
+ if (defined $document{$master}{"add_$lang"}) {
+ push @files, @{$document{$master}{"add_$lang"}};
+ }
+
+ unless (is_older($stampfile, @files)) {
+ print wrap_msg(gettext("%s don't need to be updated."),
+ $document{$master}{$lang})
+ if ($po4a_opts{"verbose"});
+ next DOC;
+ }
+ }
+
my %file_opts = %po4a_opts;
my $options = "";
if (defined $document{$master}{"options"}{"global"}) {
@@ -1017,8 +1048,22 @@
$document{$master}{$lang}, $hit, $queries,
$percent, $file_opts{"threshold"});
unlink($document{$master}{$lang}) if (-e $document{$master}{$lang});
+ unless ($po4a_opts{"force"}) {
+ touch($document{$master}{$lang}.".po4a-stamp");
+ print wrap_msg(gettext("Timestamp %s created."),
+ $document{$master}{$lang}.".po4a-stamp")
+ if ($po4a_opts{"verbose"});
+ }
next DOC;
}
+ unless ($po4a_opts{"force"}) {
+ if (-e $document{$master}{$lang}.".po4a-stamp") {
+ unlink $document{$master}{$lang}.".po4a-stamp";
+ print wrap_msg(gettext("Timestamp %s removed."),
+ $document{$master}{$lang}.".po4a-stamp")
+ if ($po4a_opts{"verbose"});
+ }
+ }
if (defined ($document{$master}{"add_$lang"})) {
foreach my $add (@{$document{$master}{"add_$lang"}}) {
@@ -1058,9 +1103,38 @@
foreach my $master (keys %document) {
next if ($master eq '');
unlink $document{$master}{$lang};
+ unlink $document{$master}{$lang}.".po4a-stamp";
}
}
}
+sub touch {
+ my $file = shift;
+ if (-e $file) {
+ utime undef, undef, $file;
+ } else {
+ sysopen(FH,$file,O_WRONLY|O_CREAT|O_NONBLOCK|O_NOCTTY)
+ or croak("Can't create $file : $!");
+ close FH or croak("Can't close $file : $!");
+ }
+}
+
+sub is_older {
+ my $file = shift;
+ my @files = @_;
+ return 1 unless (-e $file);
+ my $older = 0;
+
+ my $modtime = (stat $file)[9];
+
+ for my $f (@files) {
+ if ((stat $f)[9] > $modtime) {
+ $older = 1;
+ last;
+ }
+ }
+
+ return $older;
+}
__END__
Index: changelog
===================================================================
RCS file: /cvsroot/po4a/po4a/changelog,v
retrieving revision 1.181
retrieving revision 1.182
diff -u -d -r1.181 -r1.182
--- changelog 26 Mar 2007 21:06:47 -0000 1.181
+++ changelog 26 Mar 2007 21:40:02 -0000 1.182
@@ -1,3 +1,9 @@
+2007-03-26 Nicolas François <nicolas.francois at centraliens.net>
+
+ * po4a: Only re-generate translations if needed. Use a timestamp
+ when a translation cannot be generated. (deactivated with
+ --force).
+
2007-03-24 Nicolas François <nicolas.francois at centraliens.net>
* po4a, po4a-updatepo: Use msgmerge with the --previous switch.
More information about the Po4a-commits
mailing list