aboutsummaryrefslogtreecommitdiffstats
path: root/stattrans.pl
diff options
context:
space:
mode:
authorSteve McIntyre <steve@einval.com>2018-05-31 11:56:33 +0100
committerSteve McIntyre <steve@einval.com>2018-05-31 11:56:33 +0100
commit5f0f67595919b63f927e0cc2707d82057ce2958a (patch)
treeb486d41414afe4f92d25f1f1358cb6fba055493b /stattrans.pl
parenteaaa89e68c57e494215555abc8492cbce792f1d6 (diff)
Add an extra option to stattrans.pl to repair broken commit hashes
Add -r to fix up the errors. In such cases, we update the header in the translated file to refer to the latest version of the original.
Diffstat (limited to 'stattrans.pl')
-rwxr-xr-xstattrans.pl36
1 files changed, 34 insertions, 2 deletions
diff --git a/stattrans.pl b/stattrans.pl
index ab110bac63e..63bc0df6e57 100755
--- a/stattrans.pl
+++ b/stattrans.pl
@@ -41,9 +41,11 @@ $opt_v = 0;
$opt_d = "u";
$opt_l = undef;
$opt_b = ""; # Base URL, if not debian.org
+# Should we try to repair any broken translation hash references?
+$opt_r = 0;
# path of web stats JSON data
$opt_f = "/srv/www.debian.org/webwml/stats.json";
-getopts('h:w:b:p:t:vd:l:f:') || die;
+getopts('h:w:b:p:t:vd:l:f:r') || die;
# Replace filename globbing by Perl regexps
$opt_p =~ s/\./\\./g;
$opt_p =~ s/\?/./g;
@@ -57,6 +59,7 @@ $opt_p =~ s/$/\$/g;
'verbose' => $opt_v,
'difftype'=> $opt_d,
'hit_file'=> $opt_f,
+ 'repair' => $opt_r,
);
my $VCSHOST = "salsa";
@@ -231,6 +234,27 @@ sub get_color
}
}
+# Update the translation-check metadata header in a wml file
+sub update_file_metadata
+{
+ my $file = shift;
+ my $revision = shift;
+ my $hash = shift;
+ my $text = "";
+
+ open (IN, "< $file") or die "Can't open $file for reading: $!\n";
+ while (<IN>) {
+ if (m/^#use wml::debian::translation-check/) {
+ s/(translation="?)($revision)("?)/$1$hash$3/;
+ }
+ $text .= $_;
+ }
+ close(IN);
+ open(OUT, "> $file") or die "Can't open $file for writing: $!\n";
+ print OUT $text;
+ close OUT;
+}
+
sub check_translation
{
my ($translation, $version, $file, $orig_file) = @_;
@@ -244,7 +268,15 @@ sub check_translation
# From translation-check.wml
my $version_diff = $VCS->count_changes($orig_file, $translation, $version);
if (!defined $version_diff) {
- print "check_translation: error from count_changes for orig_file $orig_file, file $file\n";
+ print "check_translation: error from count_changes() for orig_file $orig_file, file $file\n";
+ if ($config{'repair'}) {
+ # Replace the translation reference with the most
+ # recent version of the original? Yes, they're all
+ # either really old or files with only one commit...
+ my $latest_rev_orig = $VCS->get_newest_revision($orig_file);
+ print " fixing: using rev $latest_rev_orig instead of $translation\n";
+ update_file_metadata($file, $translation, $latest_rev_orig);
+ }
} else {
if ($version_diff < 0) {
return '<gettext domain="stats">Wrong translation version</gettext>';

© 2014-2024 Faster IT GmbH | imprint | privacy policy