diff options
author | Pierre Machard <pmachard> | 2004-07-18 23:48:24 +0000 |
---|---|---|
committer | Pierre Machard <pmachard> | 2004-07-18 23:48:24 +0000 |
commit | ff709a76f3ae7d80c8ffd524a21e0e938a255293 (patch) | |
tree | ccd990f2e7097c19e8e424b7b4afa86eda296a49 /Perl/Webwml | |
parent | 9a9fa56e0bab95b30e9fc51716a7500aa76d764c (diff) |
Remove since we use dl10n now
CVS version numbers
Perl/Webwml/L10n/Db.pm: 1.15 -> 1.16(DEAD)
Perl/Webwml/L10n/Debconf.pm: 1.11 -> 1.12(DEAD)
Diffstat (limited to 'Perl/Webwml')
-rw-r--r-- | Perl/Webwml/L10n/Db.pm | 362 | ||||
-rw-r--r-- | Perl/Webwml/L10n/Debconf.pm | 471 |
2 files changed, 0 insertions, 833 deletions
diff --git a/Perl/Webwml/L10n/Db.pm b/Perl/Webwml/L10n/Db.pm deleted file mode 100644 index 29a333975c5..00000000000 --- a/Perl/Webwml/L10n/Db.pm +++ /dev/null @@ -1,362 +0,0 @@ -#!/usr/bin/perl -w - -## Copyright (C) 2001-2002 Denis Barbier <barbier@debian.org> -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -=head1 NAME - -Webwml::L10n::Db - handle database of l10n stuff - -=head1 SYNOPSIS - - use Webwml::L10n::Db; - my $l10n_db = Webwml::L10n::Db->new(); - $l10n_db->read("../data/unstable"); - foreach ($l10n_db->list_packages()) { - print "Package $_ ".$l10n_db->version($_)."\n"; - } - -=head1 DESCRIPTION - -This module is an interface with the database file used to create -webpages under C<webwml/E<lt>languageE<gt>/internaltional/l10n/>. - -=head1 METHODS - -=over 4 - -=cut - -package Webwml::L10n::Db; -use strict; -use Time::localtime; - -# Do not use ``our'' to be compatible with Perl 5.005 -use vars (qw($AUTOLOAD)); - -=item new - -This is the constructor, it only performs some initialization. - - my $l10n_db = Webwml::L10n::Db->new(); - -=cut - -sub new { - my $proto = shift; - my $class = ref($proto) || $proto; - my $self = { - data => {}, - date => 0, - # Fields below are written into file in the same order - # Package must always be the first field - # Switch is used temporarily to detect packages which - # depend on debconf and did not switch to using po-debconf. - scalar => [qw(Package Version Section Priority Maintainer PoolDir Type Upstream Switch)], - array1 => [qw(Errors Catgets Gettext)], - array2 => [qw(NLS PO TEMPLATES PODEBCONF MENU DESKTOP MAN)], - }; - $self->{methods} = {}; - foreach (@{$self->{scalar}}) { - $self->{fields}->{$_} = '$'; - } - foreach (@{$self->{array1}}) { - $self->{fields}->{$_} = '@'; - } - foreach (@{$self->{array2}}) { - $self->{fields}->{$_} = '@@'; - } - foreach (keys %{$self->{fields}}) { - $self->{methods}->{lc $_} = $_; - } - bless ($self, $class); - return $self; -} - -sub AUTOLOAD { - my $self = shift; - my $type = ref($self) or die "$self is not an object"; - my $pkg = shift; - - my $name = $AUTOLOAD; - $name =~ s/.*://; # strip fully-qualified portion - - return defined($self->{data}->{$pkg}) if $name eq 'has_package'; - - # Add a new package into database - $self->{data}->{$pkg} = {} if $name eq 'package'; - - if (! defined $self->{data}->{$pkg}) { - warn __PACKAGE__.": Package $pkg does not exist, method \`$name' skipped\n"; - return; - } - my $has = ""; - my $add = ""; - if ($name =~ s/^has_//) { - $has = "has_"; - } elsif ($name =~ s/^add_//) { - $add = "add_"; - } - - die "Can't access \`$has$name' method in class $type" - unless defined($self->{methods}->{$name}); - - my $field = $self->{methods}->{$name}; - - if ($has) { - return defined($self->{data}->{$pkg}->{$field}); - } else { - if ($#_ == -1) { - if ($self->{fields}->{$field} =~ m/@/) { - return $self->{data}->{$pkg}->{$field} || []; - } - return $self->{data}->{$pkg}->{$field}; - } - if ($self->{fields}->{$field} eq '$') { - $self->{data}->{$pkg}->{$field} = $_[0]; - } elsif ($self->{fields}->{$field} eq '@') { - $self->{data}->{$pkg}->{$field} = [] - unless defined($self->{data}->{$pkg}->{$field}) - || !$add; - push (@{$self->{data}->{$pkg}->{$field}}, @_); - } elsif ($self->{fields}->{$field} eq '@@') { - $self->{data}->{$pkg}->{$field} = [] - unless defined($self->{data}->{$pkg}->{$field}) - || !$add; - my @list = @_; - push (@{$self->{data}->{$pkg}->{$field}}, \@list); - } else { - die __PACKAGE__.":internal error: unknown data type:".$self->{fields}->{$field}."\n"; - } - } -} - -# Perl 5.6.1 complains when it does not find this routine -sub DESTROY { -} - -=item read - -Read database from a given file. Returns 1 on success and otherwise 0. - - $l10n_db->read("foo"); - -=cut - -sub read { - my $self = shift; - my $file = shift; - my $check = shift; - $check = 1 unless defined $check; - - if ($file =~ m/\.gz$/) { - open (DB,"gzip -dc $file |") || return 0; - } else { - open (DB,"< $file") || return 0; - } - - $self->{date} = <DB>; - return 0 unless defined($self->{date}); - - chomp($self->{date}); - $_ = <DB>; - return unless defined $_; - MAIN: while (1) { - my $entry = {}; - my $desc = ''; - my $last_item = 0; - my $text; - - while (<DB>) { - last if m/^\s*$/; - $desc .= $_; - } - if (!defined($_)) { - last unless $desc =~ m/\S/; - $last_item = 1; - } - - # Leading tabs are illegal, but handle them anyway - $desc =~ s/^\t/ \t/mg; - - foreach (@{$self->{scalar}}) { - if ($desc =~ m/^$_: (.*)$/m) { - if ($_ eq 'Package' && defined $self->{data}->{$1}) { - $entry = $self->{data}->{$1}; - } else { - $entry->{$_} = $1; - } - } elsif ($check && $_ ne 'Switch') { - warn "Parse error when reading $file: Package ".(defined($entry->{Package}) ? $entry->{Package} : "<unknown>").": missing \`$_' field\n"; - next MAIN; - } - } - foreach (@{$self->{array1}}) { - if ($desc =~ m/(^|\n)$_:\n(.+?)(\n\S|$)/s) { - $text = $2; - $text =~ s/^ //mg; - my @list = split(/\n\./, $text); - $entry->{$_} = \@list; - } - } - foreach (@{$self->{array2}}) { - if ($desc =~ m/(^|\n)$_:\n(.+?)(\n\S|$)/s) { - $text = $2; - $text =~ s/^ //mg; - my @list = (); - foreach my $line (split(/\n/, $text)) { - my @list2 = split('!', $line); - push(@list, \@list2); - } - $entry->{$_} = \@list; - } - } - $self->{data}->{$entry->{Package}} = $entry; - last if $last_item; - } - close DB; - return 1; -} - -=item write - -Write database into file. - - $l10n_db->write("foo"); - -=cut - -sub write { - my $self = shift; - my $file = shift; - my ($text, $line); - - if ($file =~ m/\.gz$/) { - open (DB,"| gzip -c > $file") - || die "Unable to write to $file\n"; - } else { - open (DB,"> $file") - || die "Unable to write to $file\n"; - } - - printf DB "%d-%02d-%02d\n\n", Time::localtime::localtime->year() + 1900, Time::localtime::localtime->mon() + 1, Time::localtime::localtime->mday; - foreach my $pkg (sort keys %{$self->{data}}) { - foreach (@{$self->{scalar}}) { - next unless defined($self->{data}->{$pkg}->{$_}); - print DB $_.": ".$self->{data}->{$pkg}->{$_}."\n"; - } - foreach (@{$self->{array1}}) { - next unless defined($self->{data}->{$pkg}->{$_}); - $text = join("\n\.\n", @{$self->{data}->{$pkg}->{$_}})."\n"; - $text =~ s/\n\n/\n/g; - $text =~ s/\n+$//s; - $text =~ s/^/ /mg; - print DB $_.":\n".$text."\n"; - } - foreach (@{$self->{array2}}) { - next unless defined($self->{data}->{$pkg}->{$_}); - $text = ''; - foreach $line (@{$self->{data}->{$pkg}->{$_}}) { - $text .= ' '.join('!', @{$line})."\n"; - } - print DB $_.":\n".$text; - } - print DB "\n"; - } - close (DB) || die "Unable to close $file\n"; -} - -=item list_packages - -Returns an array with the list of package names - -=cut - -sub list_packages { - my $self = shift; - return keys %{$self->{data}}; -} - -=item clear_pkg - -Reset info for a given package - - $l10n_db->clear_pkg("foo"); - -=cut - -sub clear_pkg { - my $self = shift; - my $pkg = shift; - - delete $self->{data}->{$pkg}; -} - -=item get_date - -Returns date of generation - -=cut - -sub get_date { - my $self = shift; - return $self->{date}; -} - -=item set_date - -Sets the date of generation - -=cut - -sub set_date { - my $self = shift; - my $date = shift; - $self->{date} = $date; -} - - -=back - -=head2 DATA MANIPULATION - -Data about packages can be classified within scalar values (C<package>, -C<version>, C<section>, C<priority>, C<maintainer>, C<pooldir>, C<type>, -C<upstream>), arrays (C<errors>, C<catgets>, C<gettext>), and arrays of -arrays (C<nls>, C<po>, C<templates>, C<podebconf>, C<man>, C<menu> and -C<desktop>). -Each field has a method with the same name to get and set it, e.g. - - $section = $l10n_db->section($pkg); - $l10n_db->section($pkg, "libs"); - -The first line get the section associated with the package in C<$pkg>, -whereas the second set it to C<libs>. - -Two other methods are also defined to access those data, by prefixing -field name by C<has_> and C<add_>. The former is used to ask whether -this field is defined in database, and the latter appends values for -arrays or arrays of arrays. - - if ($l10n_db->has_templates($pkg)) { - print "Package $pkg has Debconf templates\n"; - } - $l10n_db->add_po($pkg, 'po/fr.po', 'fr', '42t0f0u', 'po/adduser_3.42_po_fr.po'); - -=head1 AUTHOR - -Copyright (C) 2001-2002 Denis Barbier <barbier@debian.org> - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -=cut - -1; - diff --git a/Perl/Webwml/L10n/Debconf.pm b/Perl/Webwml/L10n/Debconf.pm deleted file mode 100644 index ee690ad1966..00000000000 --- a/Perl/Webwml/L10n/Debconf.pm +++ /dev/null @@ -1,471 +0,0 @@ -#!/usr/bin/perl -w - -## Copyright (C) 2001 Denis Barbier <barbier@debian.org> -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -=head1 NAME - -Webwml::L10n::Debconf - translation status of Debconf templates - -=head1 SYNOPSIS - - use Webwml::L10n::Debconf; - my $tmpl = Webwml::L10n::Debconf->new(); - $tmpl->read_compact($file); - my @languages = $tmpl->langs(); - foreach (sort @languages) { - my ($t,$f,$u) = $tmpl->stats($_); - print "$_:${t}t${f}f${u}u\n"; - } - -=head1 DESCRIPTION - -This module extracts informations about translation status of Debconf -templates files. - -=head1 METHODS - -=over 4 - -=cut - -package Webwml::L10n::Debconf; - -use strict; - -=item new - -This is the constructor. - - my $tmpl = Webwml::L10n::Debconf->new(); - -=cut - -sub new { - my $proto = shift; - my $class = ref($proto) || $proto; - my $self = {}; - bless ($self, $class); - $self->_init(); - return $self; -} - -sub _init { - my $self = shift; - - $self->{orig} = {}; - $self->{count} = 0; - $self->{trans} = {}; - $self->{langs} = {}; - $self->{files} = {}; -} - -=item read_compact - -Read a templates file containing all translations. An optional second -argument may be used, any non-zero value tells that this file comes with -translations in other files. In such a case no warning is raised if this -file contains translated fields, because maintainer is assumed to be -responsible for such translations. - - $tmpl->read_compact($file); - -=cut - -sub read_compact { - my $self = shift; - my $file = shift; - my $safe = shift || 0; - my ($lang, $msg); - - $self->_init(); - open (TMPL, "< $file") - || die "Unable to read file $file\n"; - - my $tmpl = ''; - my $line = 0; - while (<TMPL>) { - chomp; - $line ++; - if (m/^[A-Z][a-z]*-[A-Za-z_]+-fuzzy:/) { - warn "$file:$line: fuzzy-fields-in-templates\n"; - goto SKIP; - } - if ((!$safe) && m/^[A-Z][a-z]*-[A-Za-z_]+:/) { - warn "$file:$line: translated-fields-in-master-templates\n"; - # Display this message only once - $safe = 1; - } - if (s/^Template:\s*//) { - $tmpl = $_; - $self->{orig}->{$tmpl} = {}; - } elsif (s/^(Choices):\s*//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - $self->{orig}->{$tmpl}->{choices} = $_; - $self->{count} ++; - } elsif (s/^(Description):\s*//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - $msg = $_ . "\n"; - while (<TMPL>) { - $line ++; - last if (!defined($_) || m/^\S/ || m/^$/m); - $msg .= $_; - } - $msg =~ s/^\s+//gm; - $msg =~ s/\s+$//gm; - $msg =~ tr/ \t\n/ /s; - $self->{orig}->{$tmpl}->{description} = $msg; - $self->{count} ++; - last unless defined($_); - $line --; - redo; - } elsif (s/^(Choices-(.*?)):\s*//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - $lang = $2; - unless (defined($self->{langs}->{$lang})) { - $self->{langs}->{$lang} = 1; - $self->{trans}->{$lang}->{count} = 0; - $self->{trans}->{$lang}->{fuzzy} = 0; - } - $self->{trans}->{$lang}->{count} ++; - } elsif (s/^(Description-(.*?)):\s+//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - $lang = $2; - unless (defined($self->{langs}->{$lang})) { - $self->{langs}->{$lang} = 1; - $self->{trans}->{$lang}->{count} = 0; - $self->{trans}->{$lang}->{fuzzy} = 0; - } - do { - $_ = <TMPL>; - $line ++; - } until (!defined($_) || m/^\S/ || m/^$/m); - $self->{trans}->{$lang}->{count} ++; - last unless defined($_); - $line --; - redo; - } elsif (m/^\s*$/) { - $tmpl = ''; - } elsif (m/^(Type|Default)/) { - # Ignored fields - } else { - warn "$file:$line: Wrong input line:\n $_\n"; - } - next; - - SKIP: - while (<TMPL>) { - $line ++; - last if (!defined($_) || m/^\S/ || m/^$/m); - } - last unless defined($_); - $line --; - redo; - } - close(TMPL); -} - -=item read_dispatched - -Read templates contained in several files. First argument is the English file, -all other arguments are translated templates files. - - @trans = qw(templates.de templates.fr templates.ja templates.nl); - $tmpl->read_dispatched('templates', @trans); - -=cut - -sub read_dispatched { - my $self = shift; - my $file = shift; - - $self->_init(); - $self->read_compact($file, 1); - $self->{trans} = {}; - $self->{langs} = {}; - foreach my $trans (@_) { - $self->_read_dispatched($trans); - } -} - -sub _read_dispatched { - my $self = shift; - my $file = shift; - my ($lang, $msg, $status_c, $status_d); - - open (TMPL, "< $file") - || die "Unable to read file $file\n"; - - my $tmpl = ''; - my $line = 0; - my $ext = $file; - $ext =~ s/.*\.//; - while (<TMPL>) { - chomp; - $line ++; - if (m/^[A-Z][a-z]*-[A-Za-z_]+-fuzzy:/) { - warn "$file:$line: fuzzy-fields-in-templates\n"; - goto SKIP; - } - if (s/^Template:\s*//) { - $tmpl = $_; - $status_c = $status_d = ''; - unless (defined $self->{orig}->{$tmpl}) { - warn "$file:$line: translated-templates-not-in-original $_\n"; - while (<TMPL>) { - $line ++; - last if (!defined($_) || m/^$/); - } - last unless defined($_); - $line --; - redo; - } - } elsif (s/^(Choices):\s*//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - next unless defined $self->{orig}->{$tmpl}; - if (defined($self->{orig}->{$tmpl}->{choices}) && - $_ eq $self->{orig}->{$tmpl}->{choices}) { - $status_c = 'count'; - } else { - $status_c = 'fuzzy'; - } - } elsif (s/^(Choices-(.*?)):\s*//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - $lang = $2; - if ($lang ne $ext) { - warn "$file:$line: lang-mismatch-in-translated-templates\n" - } else { - unless (defined($self->{langs}->{$lang})) { - $self->{langs}->{$lang} = 1; - $self->{trans}->{$lang}->{count} = 0; - $self->{trans}->{$lang}->{fuzzy} = 0; - } - if ($status_c) { - $self->{trans}->{$lang}->{$status_c} ++; - } else { - warn "$file:$line: original-fields-removed-in-translated-templates\n"; - } - $status_c = ''; - } - } elsif (s/^(Description):\s*//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - next unless defined $self->{orig}->{$tmpl}; - $msg = $_ . "\n"; - while (<TMPL>) { - $line ++; - last if (!defined($_) || m/^\S/ || m/^$/m); - $msg .= $_; - } - $msg =~ s/^\s+//gm; - $msg =~ s/\s+$//gm; - $msg =~ tr/ \t\n/ /s; - if (defined($self->{orig}->{$tmpl}->{description}) && - $msg eq $self->{orig}->{$tmpl}->{description}) { - $status_d = 'count'; - } else { - $status_d = 'fuzzy'; - } - last unless defined($_); - $line --; - redo; - } elsif (s/^(Description-(.*?)):\s+//) { - if ($tmpl eq '') { - warn "$file:$line: \`$1' field found before \`Template'\n"; - goto SKIP; - } - $lang = $2; - if ($lang ne $ext) { - warn "$file:$line: lang-mismatch-in-translated-templates\n"; - do { - $_ = <TMPL>; - $line ++; - } until (!defined($_) || m/^\S/ || m/^$/m); - } else { - if (defined($self->{files}->{$lang})) { - die "Lang \`$lang' found in \`$file' and \`$self->{files}->{$lang}'\n" - unless $self->{files}->{$lang} eq $file; - } else { - $self->{files}->{$lang} = $file; - } - unless (defined($self->{langs}->{$lang})) { - $self->{langs}->{$lang} = 1; - $self->{trans}->{$lang}->{count} = 0; - $self->{trans}->{$lang}->{fuzzy} = 0; - } - do { - $_ = <TMPL>; - $line ++; - } until (!defined($_) || m/^\S/ || m/^$/m); - if ($status_d) { - $self->{trans}->{$lang}->{$status_d} ++; - } else { - warn "$file:$line: original-fields-removed-in-translated-templates\n"; - } - $status_d = ''; - } - last unless defined($_); - $line --; - redo; - } elsif (m/^\s*$/) { - $tmpl = ''; - $status_c = $status_d = ''; - } elsif (m/^(Type|Default)/) { - # Ignored fields - } else { - warn "$file:$line: Wrong input line:\n $_\n"; - } - next; - - SKIP: - while (<TMPL>) { - $line ++; - last if (!defined($_) || m/^\S/ || m/^$/); - } - last unless defined($_); - $line --; - redo; - } - close(TMPL); -} - -=item langs - -Return the languages in which this templates file is translated. - - my @list = $tmpl->langs(); - -=cut - -sub langs { - my $self = shift; - return keys %{$self->{langs}}; -} - -=item filename - -When templates are dispatched into several files, return the filename in -which the language passed as argument is found. - - my $filename = $tmpl->filename("de"); - -=cut - -sub filename { - my $self = shift; - my $lang = shift; - return (defined($self->{files}->{$lang}) ? - $self->{files}->{$lang} : ''); -} - -=item count - -Return the number of translatable strings in this templates file. - - my $number = $tmpl->count(); - -=cut - -sub count { - my $self = shift; - return $self->{count}; -} - -=item stats - -With an argument, return an array consisting of the number of -translated, fuzzy and untranslated strings for the language given as -argument. -Without argument, return a hash array indexed by language and returning -an array of the number of translated, fuzzy and untranslated strings. - - my ($t, $f, $u) = $tmpl->stats("de"); - my %stats = $tmpl->stats(); - foreach (keys %stats) { - print $_.':'. $stats{$_}->[0].'t'.$stats{$_}->[1].'f'. - $stats{$_}->[2]."u\n"; - } - -=cut - -sub stats { - my $self = shift; - my $lang; - if (@_) { - $lang = shift; - if (defined($self->{langs}->{$lang})) { - return ($self->{trans}->{$lang}->{count}, - $self->{trans}->{$lang}->{fuzzy}, - $self->{count} - - $self->{trans}->{$lang}->{fuzzy} - - $self->{trans}->{$lang}->{count}); - } else { - return (0,0,0); - } - } else { - my %stats = (); - foreach $lang (keys %{$self->{langs}}) { - $stats{$lang} = [ - $self->{trans}->{$lang}->{count}, - $self->{trans}->{$lang}->{fuzzy}, - $self->{count} - - $self->{trans}->{$lang}->{fuzzy} - - $self->{trans}->{$lang}->{count} - ]; - } - return %stats; - } -} - -=item entries - -Return an array containing all Debconf ids found in this templates file. - - my @ids = $tmpl->entries(); - -=cut - -sub entries { - my $self = shift; - return keys %{$self->{orig}}; -} - -=back - -=head1 AUTHOR - -Copyright (C) 2001 Denis Barbier <barbier@debian.org> - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -=cut - -1; - |