[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Notifying readers when documents are too old



	It seems I have a working way to do this, alas, it changes, slightly
how translators should add the information on which version they have
translated (we could easily move from one format to another, whoever)


	There need to be some changes in the Make.dep.generic in order to
give eperl information on what file he is handling, the only way I have
been able to do this is:

%.$(LANGUAGE).html : %.wml $(TEMPLDIR)/template.wml $(TEMPLDIR)/languages.wml
        $(WML) -D file=$(firstword $^) $(<F)

	Note the -D that wml will give to eperl, this will allow it to parse
the information in the CVS/Entries file in order to find the version number
he has to check with.

	Including this in the head of any translated file
#use wml::debian::translation-check translation="1.4"

	and adding to the template the following file (translation-check.wml):
(I have commented it thoroughly)
------------------------------------------------------------
#use wml::std::tags

<perl>
sub check_translation {

my ($translation) = @_;
# $file is give via a -D in the wml command line

# This is the maximum difference between a translated
# document and the original before printing the warning
$max_versions = 5;
# directory where the original source is kept
$original_dir = "../english";

# TODO: Should do error checking here if file does not exist...
open (MAKE,"<Makefile");
# We could also do this same grepping ?faster?
while ($line = <MAKE>)
{
        chomp $line;
        if ( $line =~ /^WMLBASE\s*=\s*(.*)/ )
        {
                $wmlbase = $1;
        }
        if ( $line =~ /^CUR_DIR\s*=\s*(.*)/ )
        {
                $current_dir = $1;
        }
        last if $wmlbase and $current_dir;
}
close MAKE;

# Now read the original CVS file in Opening 
# $wmlbase/$original_dir/$current_dir/CVS/Entries"
open (CVS_ENTRY,"<$wmlbase/$original_dir/$current_dir/CVS/Entries");
while ( $line =<CVS_ENTRY> )
{
        chomp $line;
        print "Reading $line \n";
        if ( $line =~ /\/\Q$file\E\/([\d\.]*)/ ) {
                $version = $1;
        }
                $version = $1;
        }
        last if $version;
}
# TODO: Should check if version not found (maybe yell?)

# Here we compare the original version with the translated one
# and if their last numbers are too further apart report
# to the user

# TODO: Also check major number
if ( $version =~ /\.(\d*)$/ )
{ $last_number = $1; }
else{ print STDERR "CVS Entry $file version number not as expected: $version not in expected format\n";
  return 1;
}
if ( $translation =~ /\.(\d*)$/ )
{ $last_translated_number = $1;}
else
{ print STDERR "Call to the subroutine has not been made as expected: $translation not in expected format\n";
  return 1;
}

if ( $last_number - $last_translated_number > $max_versions )
{
# TODO:This should be printed using tags in order to tell the
# user in his language
        print "<B>This translations is too out of date<B><BR>";
}
close CVS_ENTRY;
}</perl>
<: &check_translation ( $(translation) ) :>
----------------------------------------------------------------------

	Does the trick, I have not been able to make it work (yet) with
the inclusion also of #use wml::debian::mainpage title="whatever".

	What the script does is the following:

1.- it receives the translation as a variable (this is the change we had
to make to all translated files, from
<!--translation 1.44-->
to
#use wml::debian::translation-check translation="1.44"

(easy to do automagically with perl :)

2.- it opens the CVS/Entries file of the directory currently working in
but in the english/ directory, taking this information from the
Makefile in the current dir.

3.- find the version number of the same file we are compiling in that dir 
and compare it to our number (this is why we need to know which file we
are processing and thus the -D swith)

4.- if the different is too big print in the file a warning about this.

	Well, as I've said before I cannot make it work under the
'#use wml::debian::template title=' header,  in case you wonder I receive
the following error (no clue as to where is the problem, but I'm no wml
expert)

$ make related_links.es.html
wml -q -o UNDEFuES:related_links.es.html   -D file=related_links.wml
related_links.wml
ePerl:Error: Perl parsing error (interpreter rc=2)

---- Contents of STDERR channel: ---------
Can't load '/usr/local/lib/site_perl/i386-linux/auto/GD/GD.so' for module
GD: /usr/local/lib/site_perl/i386-linux/auto/GD/GD.so: undefined symbol:
Perl_markstack_ptr at /usr/lib/perl5/5.005/i386-linux/DynaLoader.pm line
169.

 at /tmp/wml.11880.tmp1 line 167
BEGIN failed--compilation aborted at /tmp/wml.11880.tmp1 line 167.
------------------------------------------
** WML:Break: Error in Pass 3 (rc=74).
make: *** [related_links.es.html] Error 1


	Well, I hope this is useful for our site.

	Regards

	Javi

PS: Sorry for the bad perl programming, I'm no expert :P


Reply to: