#use wml::std::tags
#use wml::debian::languages
#use wml::debian::common_tags
# This file is used to track when translations go out-of-date, and it is
# used by including this in the head of the translated file:
#
# #use wml::debian::translation-check translation="XXXXXXXXXXXXXXXXXX"
#
# where XXXXXXXXXXXXXXXXXX is the current git revision of the file you
# have translated.
#
# There are also some additional parameters that you can use on the #use
# line:
#
# original="language"
# where language is the name of the language you are translating from, if
# not english. The name must correspond to the top-level subdirectory, and
# to the name in languages.wml
#
# mindelta="number"
# which defines the maximum difference in git revisions before the
# translation is considered aged. The default value is 1. For less important
# pages, set it to 2, which means that not every change is considered making
# the translation aged. The value for the tag is displayed.
#
# maxdelta="number"
# which defines the maximum difference in git revisions before the
# translation is considered to be outdated (and the value of the
# tag is displayed). The default value is 5. For very important pages, set
# it to be less. A value of 1 means that every change is considered making
# the translation outdated.
# This is the message that is displayed if the translation is aged.
# (min_delta <= difference < max_delta)
Note: The original document is newer than this translation.
# This is the message that is displayed if the translation is too old.
# (difference >= max_delta)
Warning! This translation is too out of date, please see the original.
# This is the message that is displayed if the referenced original file
# no longer exists.
Note: The original document of this translation no longer exists.
# This is the message that is displayed if the translation appears to
# be newer than the referenced original file. This should never
# happen!
Wrong translation version!
# Grotty, but it works...
use lib "Perl";
use lib "../Perl";
use lib "../../Perl";
use lib "../../../Perl";
use lib "../../../../Perl";
use lib "../../../../../Perl";
use lib "../../../../../../Perl";
use Local::VCS ':all';
sub check_translation {
# Input parameters:
my ($translation, $file, $original, $mindelta, $maxdelta, $force_file) = @_;
my $parents, $level, $relative_dir, $output;
my @relative_dir = ();
# This is the maximum difference between a translated
# document and the original before considering it outdated
$max_versions = $maxdelta || 5;
# This is the maximum difference between a translated
# document and the original before considering it aged
$min_versions = $mindelta || 1;
# Set this to >= 1 to get debugging output.
# Remember, if you commit to git this needs to be set to 0!
$debug = 0;
# This is the language code of the original (to make a link)
$original_lang = $original ? $langs{$original} : "en";
$link = $file;
$link =~ s/\.(wml|src)$//;
$link .= ".$original_lang.html";
# This is the directory where the original source is kept
$original_dir = $original ? "$original" : "english";
# some brown paper bag code to generate path to the original file
@full_directory_name = split '/', $WML_SRC_DIRNAME;
$dir = pop @full_directory_name;
while ($dir) {
# below condition is lame, it only works for webwml and cdimage trees
if ($dir ne "webwml" && $dir ne "cdimage") { $level++; } else { last; }
push @relative_dir, $dir;
$dir = pop @full_directory_name;
}
for (; $level > 0; $level--) { $parents .= "../"; }
pop @relative_dir;
@relative_dir = reverse @relative_dir;
$relative_dir = join '/', @relative_dir;
my $orig_file = "$parents/$original_dir/$relative_dir/$file";
if (defined $force_file && length($force_file) > 1) {
if ($debug) {
print "Ignoring $file, forcing to $force_file instead\n";
print "original $orig_file\n";
}
$orig_file = "$parents/$original_dir/$force_file";
if ($debug) {
print "now $orig_file\n";
}
}
my $VCS = Local::VCS->new();
my %file_info = $VCS->file_info($orig_file);
$version = $file_info{'cmt_rev'};
unless ($version)
{
die "Could not get revision number - bug in script?\n";
}
my $version_diff = $VCS->count_changes($orig_file, $translation, $version);
# Here we compare the original version with the translated one and print
# a note for the user if their first or last numbers are too far apart
print "Comparing original $version to translation version $translation\n" if ($debug >= 1);
$output = '';
if (!defined $version) {
$output = qq()
} else {
if ($version_diff < 0) {
# Shouldn't ever happen unless people have broken the pages
# manually
$output = qq()
} elsif ( $version_diff >= $max_versions ) {
$output = qq()
} elsif ( $version_diff >= $min_versions ) {
$output = qq()
}
}
if ($output ne "") {
$output =~ s/^\s+//m; # removes whitespace at the beginning
$output =~ s/\s+$//m; # removes whitespace at the end
$output =~ s/\n/ /sg; # replaces linebreaks with whitespace
print "";
}
}
# The call to the subroutine is done here
{#check_trans#:\
<: check_translation ("$(translation)","$WML_SRC_FILENAME","$(original)","$(mindelta)","$(maxdelta)","$(force_file)") :>\
:#check_trans#}
# This template was originally made by Javier Fernández-Sanguino, described
# in a proposal made around last week of August 1999. Please check the
# debian-www mailing list archives and
# webwml/english/devel/website/uptodate.wml for more information on this.