aboutsummaryrefslogtreecommitdiffstats
path: root/english/template/debian/translation-check.wml
blob: 33c43107f33d93b8ef65163910b783fc563898b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#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 <aged/> 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 <outdated/>
# 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)
<define-tag translationaged>
  <gettext><em>Note:</em> The <a href="$link">original document</a> is newer than this translation.</gettext>
</define-tag>

# This is the message that is displayed if the translation is too old.
# (difference >= max_delta)
<define-tag translationoutofdate>
  <gettext>Warning! This translation is too out of date, please see the <a href="$link">original</a>.</gettext>
</define-tag>

# This is the message that is displayed if the referenced original file
# no longer exists.
<define-tag originalgone>
  <gettext><em>Note:</em> The original document of this translation no longer exists.</gettext>
</define-tag>

# This is the message that is displayed if the translation appears to
# be newer than the referenced original file. This should never
# happen!
<define-tag originalolder>
    <gettext>Wrong translation version!</gettext>
</define-tag>

<perl>
<protect pass="2">

# 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 <shrug>
	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);

    </protect>
	$output = '';
    if (!defined $version) {
	$output = qq(<originalgone/>)
    } else {

	if ($version_diff < 0) {
	    # Shouldn't ever happen unless people have broken the pages
	    # manually
	    $output = qq(<strong><originalolder/></strong>)
	} elsif ( $version_diff >= $max_versions ) {
	    $output = qq(<strong><translationoutofdate/></strong>)
	} elsif ( $version_diff >= $min_versions ) {
	    $output = qq(<translationaged/>)
	}
    }

    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 "<div class=\"trans-note\"><p>$output</p></div>";
    }

}
</perl>

# 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.

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