[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Report.pm, tp/Texinfo/Translations.p
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Report.pm, tp/Texinfo/Translations.pm, tp/Texinfo/Convert/Converter.pm, tp/Texinfo/Convert/Text.pm, tp/Texinfo/ParserNonXS.pm, tp/Texinfo/XS/parsetexi/Parsetexi.pm: move gdt() and string translation related code from tp/Texinfo/Report.pm to newly created tp/Texinfo/Translations.pm. |
Date: |
Tue, 31 Aug 2021 17:04:17 -0400 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 44e0dd1 * tp/Texinfo/Report.pm, tp/Texinfo/Translations.pm,
tp/Texinfo/Convert/Converter.pm, tp/Texinfo/Convert/Text.pm,
tp/Texinfo/ParserNonXS.pm, tp/Texinfo/XS/parsetexi/Parsetexi.pm: move gdt() and
string translation related code from tp/Texinfo/Report.pm to newly created
tp/Texinfo/Translations.pm.
44e0dd1 is described below
commit 44e0dd1c2d3a1e8029f9fad182491ba85b46454a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Aug 31 23:03:48 2021 +0200
* tp/Texinfo/Report.pm, tp/Texinfo/Translations.pm,
tp/Texinfo/Convert/Converter.pm, tp/Texinfo/Convert/Text.pm,
tp/Texinfo/ParserNonXS.pm, tp/Texinfo/XS/parsetexi/Parsetexi.pm:
move gdt() and string translation related code from
tp/Texinfo/Report.pm to newly created tp/Texinfo/Translations.pm.
---
ChangeLog | 8 +
tp/Texinfo/Convert/Converter.pm | 3 +-
tp/Texinfo/Convert/Text.pm | 2 +-
tp/Texinfo/ParserNonXS.pm | 4 +-
tp/Texinfo/Report.pm | 350 +++---------------------------
tp/Texinfo/{Report.pm => Translations.pm} | 296 +------------------------
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 5 +-
tp/t/automatic_nodes.t | 14 +-
tp/t/do_master_menu.t | 12 +-
tp/texi2any.pl | 1 +
10 files changed, 82 insertions(+), 613 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dd6db50..2037015 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2021-08-31 Patrice Dumas <pertusus@free.fr>
+ * tp/Texinfo/Report.pm, tp/Texinfo/Translations.pm,
+ tp/Texinfo/Convert/Converter.pm, tp/Texinfo/Convert/Text.pm,
+ tp/Texinfo/ParserNonXS.pm, tp/Texinfo/XS/parsetexi/Parsetexi.pm:
+ move gdt() and string translation related code from
+ tp/Texinfo/Report.pm to newly created tp/Texinfo/Translations.pm.
+
+2021-08-31 Patrice Dumas <pertusus@free.fr>
+
* tp/texi2any.pl: use separate opened files informations
for each of the files opened in texi2any.pl and add to
the opened files list.
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index d9d0945..1a4a98d 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -35,7 +35,7 @@ use Carp qw(cluck);
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-@ISA = qw(Exporter Texinfo::Report);
+@ISA = qw(Exporter Texinfo::Report Texinfo::Translations);
%EXPORT_TAGS = ( 'all' => [ qw(
xml_protect_text
@@ -254,6 +254,7 @@ sub converter(;$)
$converter->{'output_files'} = {};
require Texinfo::Report;
+ require Texinfo::Translations;
# 'require' here instead of 'use' at top of file to cut down run time of
# 'texi2any --help'
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 4cba7b5..cc02fa2 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -380,7 +380,7 @@ sub _convert($;$)
my $save_lang = $options->{'converter'}->get_conf('documentlanguage');
$options->{'converter'}->{'documentlanguage'}
= $root->{'extra'}->{'documentlanguage'};
- my $tree = Texinfo::Report::gdt($options->{'converter'},
+ my $tree = Texinfo::Translations::gdt($options->{'converter'},
$root->{'text'});
$result = _convert($tree, $options);
$options->{'converter'}->{'documentlanguage'} = $save_lang;
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 1504b8e..d94b4f0 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -60,9 +60,11 @@ use Texinfo::Convert::NodeNameNormalization;
# in error messages, and for macro body expansion
use Texinfo::Convert::Texinfo;
+use Texinfo::Translations;
+
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-@ISA = qw(Exporter Texinfo::Report);
+@ISA = qw(Exporter Texinfo::Translations);
our $module_loaded = 0;
sub import {
diff --git a/tp/Texinfo/Report.pm b/tp/Texinfo/Report.pm
index 0326af5..5eb995a 100644
--- a/tp/Texinfo/Report.pm
+++ b/tp/Texinfo/Report.pm
@@ -1,4 +1,4 @@
-# Report.pm: prepare error messages and translate strings.
+# Report.pm: prepare error messages.
#
# Copyright 2010-2020 Free Software Foundation, Inc.
#
@@ -17,13 +17,14 @@
#
# Original author: Patrice Dumas <pertusus@free.fr>
+package Texinfo::Report;
+
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter);
%EXPORT_TAGS = ( 'all' => [ qw(
errors
- gdt
) ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
@@ -31,22 +32,13 @@ use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@EXPORT = qw(
);
-package Texinfo::Report;
-
use 5.00405;
use strict;
# for fileparse
use File::Basename;
-use POSIX qw(setlocale LC_ALL);
use Locale::Messages;
-# to be able to load a parser if none was given to gdt.
-use Texinfo::Parser;
-
-# we want a reliable way to switch locale for the document
-# strings translations so we don't use the system gettext.
-Locale::Messages->select_package ('gettext_pp');
my $messages_textdomain = 'texinfo';
@@ -227,246 +219,19 @@ sub file_line_error($$$;$)
}
-# i18n
-
-my $DEFAULT_LANGUAGE = 'en';
-
-
-my $strings_textdomain = 'texinfo_document';
-
-
-# libintl converts between encodings but doesn't decode them into the
-# perl internal format. This is only called if the encoding is a proper
-# perl encoding.
-sub _encode_i18n_string($$)
-{
- my $string = shift;
- my $encoding = shift;
- return Encode::decode($encoding, $string);
-}
-
-# Get document translation - handle translations of in-document strings.
-# Return a parsed Texinfo tree
-sub gdt($$;$$)
-{
- my ($self, $message, $context, $type) = @_;
-
- my $re = join '|', map { quotemeta $_ } keys %$context
- if (defined($context) and ref($context));
-
- my $saved_LC_ALL = POSIX::setlocale(LC_ALL);
- my $saved_LANGUAGE = $ENV{'LANGUAGE'};
-
- # We need to set LC_MESSAGES to a valid locale other than "C" or "POSIX"
- # for translation via LANGUAGE to work. (The locale is "C" if the
- # tests are being run.)
- # Set LC_ALL rather than LC_MESSAGES for Perl for MS-Windows.
-
- my $locale;
- our $working_locale;
- if ($working_locale) {
- $locale = POSIX::setlocale(LC_ALL, $working_locale);
- }
- if (!$locale) {
- $locale = POSIX::setlocale(LC_ALL, "en_US.UTF-8");
- }
- if (!$locale) {
- $locale = POSIX::setlocale(LC_ALL, "en_US")
- }
- our $locale_command;
- if (!$locale and !$locale_command) {
- $locale_command = "locale -a";
- my @locales = split("\n", `$locale_command`);
- if ($? == 0) {
- for my $try (@locales) {
- next if $try eq 'C' or $try eq 'POSIX';
- $locale = POSIX::setlocale(LC_ALL, $try);
- last if $locale;
- }
- }
- }
- $working_locale = $locale;
-
-
- Locale::Messages::textdomain($strings_textdomain);
-
- # FIXME do this only once when encoding is seen (or at beginning)
- # instead of here, each time that gdt is called?
- my $encoding;
- if ($self->get_conf('OUTPUT_ENCODING_NAME')) {
- $encoding = $self->get_conf('OUTPUT_ENCODING_NAME');
- }
- Locale::Messages::bind_textdomain_codeset($strings_textdomain, $encoding)
- if ($encoding and $encoding ne 'us-ascii');
- if (!($encoding and $encoding eq 'us-ascii')) {
- my $perl_encoding;
- if ($self->get_conf('OUTPUT_PERL_ENCODING')) {
- $perl_encoding = $self->get_conf('OUTPUT_PERL_ENCODING');
- }
- if ($perl_encoding) {
- Locale::Messages::bind_textdomain_filter($strings_textdomain,
- \&_encode_i18n_string, $perl_encoding);
- }
- }
-
- # This needs to be dynamic in case there is an untranslated string
- # from another language that needs to be translated.
- # FIXME make it an argument
- my $lang = $self->get_conf('documentlanguage');
- $lang = $DEFAULT_LANGUAGE if (!defined($lang));
- my @langs = ($lang);
- if ($lang =~ /^([a-z]+)_([A-Z]+)/) {
- my $main_lang = $1;
- my $region_code = $2;
- push @langs, $main_lang;
- }
-
- my $locales = '';
-
- foreach my $language (@langs) {
- if ($encoding) {
- $locales .= "$language.$encoding:";
- } else {
- $locales .= "$language:";
- }
- # always try us-ascii, the charset should always be a subset of
- # all charset, and should resort to @-commands if needed for non
- # ascii characters
- if (!$encoding or ($encoding and $encoding ne 'us-ascii')) {
- $locales .= "$language.us-ascii:";
- }
- }
- $locales =~ s/:$//;
-
- Locale::Messages::nl_putenv("LANGUAGE=$locales");
-
- my $translated_message = Locale::Messages::gettext($message);
-
- Locale::Messages::textdomain($messages_textdomain);
- if (!defined($saved_LANGUAGE)) {
- delete ($ENV{'LANGUAGE'});
- } else {
- $ENV{'LANGUAGE'} = $saved_LANGUAGE;
- }
- if (defined($saved_LC_ALL)) {
- POSIX::setlocale(LC_ALL, $saved_LC_ALL);
- } else {
- POSIX::setlocale(LC_ALL, '');
- }
-
- my $translation_result = $translated_message;
-
- if ($type and $type eq 'translated_text') {
- if (defined($re)) {
- # next line taken from libintl perl, copyright Guido. sub __expand
- $translation_result =~ s/\{($re)\}/defined $context->{$1} ?
$context->{$1} : "{$1}"/ge;
- }
- return $translation_result;
- }
-
- my $parser_conf;
- # we change the substituted brace-enclosed strings to values, that
- # way they are substituted, including when they are Texinfo trees.
- # a _ is prepended to avoid clashing with other values, although since
- # the parser is a new one there should not be any problem anyway.
- if (defined($re)) {
- # next line taken from libintl perl, copyright Guido. sub __expand
- $translation_result =~ s/\{($re)\}/\@txiinternalvalue\{$1\}/g;
- }
-
- # Don't reuse the current parser itself, as (tested) the parsing goes
- # wrong, certainly because the parsed text can affect the parser state.
- my $current_parser;
- if (ref($self) eq 'Texinfo::Parser') {
- $current_parser = $self;
- } elsif ($self->{'parser'}) {
- $current_parser = $self->{'parser'};
- }
-
- if ($current_parser) {
- # 'TEST' can be used fot @today{} expansion.
- # FIXME use get_conf
- foreach my $duplicated_conf ('clickstyle', 'kbdinputstyle', 'DEBUG',
- 'TEST') {
- $parser_conf->{$duplicated_conf} = $current_parser->{$duplicated_conf}
- if (defined($current_parser->{$duplicated_conf}));
- }
- }
- $parser_conf->{'accept_internalvalue'} = 1;
- my $parser = Texinfo::Parser::simple_parser($parser_conf);
- if ($parser->{'DEBUG'}) {
- print STDERR "GDT $translation_result\n";
- }
-
- my $tree = $parser->parse_texi_line($translation_result);
- my $registrar = $parser->registered_errors();
- my ($errors, $errors_count) = $registrar->errors();
- if ($errors_count) {
- warn "translation $errors_count error(s)\n";
- warn "translated message: $translated_message\n";
- warn "Error messages: \n";
- foreach my $error_message (@$errors) {
- warn $error_message->{'error_line'};
- }
- }
- $tree = _substitute ($tree, $context);
- return $tree;
-}
-
-sub _substitute_element_array ($$);
-sub _substitute_element_array ($$) {
- my $array = shift; my $context = shift;
-
- @{$array} = map {
- if ($_->{'cmdname'} and $_->{'cmdname'} eq 'txiinternalvalue') {
- my $name = $_->{'args'}->[0]->{'text'};
- if (ref($context->{$name}) eq 'HASH') {
- $context->{$name};
- } elsif (ref($context->{$name}) eq 'ARRAY') {
- @{$context->{$name}};
- } elsif (ref($context->{$name}) eq '') {
- {'text' => $context->{$name}};
- } else {
- (); # undefined - shouldn't happen?
- }
- } else {
- _substitute($_, $context);
- ( $_ );
- }
- } @{$array};
-}
-
-# Recursively substitute @txiinternalvalue elements in $TREE with
-# their values given in $CONTEXT.
-sub _substitute ($$);
-sub _substitute ($$) {
- my $tree = shift; my $context = shift;
-
- if ($tree->{'contents'}) {
- _substitute_element_array ($tree->{'contents'}, $context);
- }
-
- if ($tree->{'args'}) {
- _substitute_element_array ($tree->{'args'}, $context);
- }
-
- return $tree;
-}
-
-
1;
__END__
=head1 NAME
-Texinfo::Report - Error storing and string translations for Texinfo modules
+Texinfo::Report - Error storing for Texinfo modules
=head1 SYNOPSIS
- @ISA = qw(Texinfo::Report);
+ use Texinfo::Report;
- $registrar->Texinfo::Report::new();
+ my $registrar = Texinfo::Report::new();
if ($warning_happened) {
$registrar->line_warn($converter, sprintf(__("\@%s is wrongly used"),
@@ -478,86 +243,39 @@ Texinfo::Report - Error storing and string translations
for Texinfo modules
warn $error_message->{'error_line'};
}
- my $tree_translated = $converter->gdt('See {reference} in @cite{{book}}',
- {'reference' => $tree_reference,
- 'book' => {'text' => $book_name}});
-
-
=head1 DESCRIPTION
-The Texinfo::Report module helps with string translations and error
-handling. It is used by the Texinfo modules Texinfo::Parser and
-Texinfo::Convert::Converter. To use this module, initialize the
-Texinfo::Report object with C<Texinfo::Report::new()>.
+The Texinfo::Report module helps with error handling. It is
+used by the Texinfo modules Texinfo::Parser and
+Texinfo::Convert::Converter. To use this module, either create
+a new Texinfo::Report object or initialize another object
+such as to be able to call Texinfo::Report methods. In any
+case, C<Texinfo::Report::new()> is called to setup the module.
-Besides the C<new> method, C<gdt> is used for string translations,
-C<errors> for reporting errors, and the other methods to store errors
-(and warnings).
+Besides the C<new> method, C<errors> is used for reporting errors, and the
+other methods to store errors (and warnings).
=head1 METHODS
No method is exported in the default case.
-The C<new> method initializes Texinfo::Report related fields:
-
- $converter->Texinfo::Report::new()
-
-The C<gdt> method is used to translate strings to be output in
-converted documents, and return a texinfo tree.
+The C<new> method initializes Texinfo::Report related fields.
+The errors collected are available through the C<errors> method, the other
+methods allow registering errors and warnings.
=over
-=item $tree = $converter->gdt($string, $replaced_substrings, $mode)
+=item my $registrar = Texinfo::Report::new()
-The I<$string> is a string to be translated. In the default case,
-the function returns a Texinfo tree, as the string is
-interpreted as Texinfo code after
-translation. I<$replaced_substrings> is an optional
-hash reference specifying some
-substitution to be done after the translation. The key of
-the I<$replaced_substrings> hash reference identifies what is to
-be substituted, and the value is some string, texinfo tree or array content
-that is substituted in the resulting texinfo tree.
-In the string to be translated word in brace matching keys of
-I<$replaced_substrings> are replaced.
+=item $converter->Texinfo::Report::new()
-I<$mode> is an optional string which may modify how the function
-behaves. The possible values are
-
-=over
-
-=item translated_text
-
-In that case the string is not considered to be Texinfo, a plain string
-that is returned after translation and substitution. The substitutions
-may only be strings in that case.
-
-=back
+If called without argument, a Texinfo::Report object is initialized and
+returned. This is how the module is used in the Texinfo Parsers, as
+a separate object.
-For example in the following call, the string
-I<See {reference} in @cite{{book}}> is translated, then
-parsed as a Texinfo string, with I<{reference}> substituted by
-I<$tree_reference> in the resulting tree, and I<{book}>
-replaced by the associated texinfo tree text element:
-
- $tree = $converter->gdt('See {reference} in @cite{{book}}',
- {'reference' => $tree_reference,
- 'book' => {'text' => $book_name}});
-
-C<gdt> uses the information in the I<$converter> to know the
-encoding and documentlanguage. More precisely,
-C<< $converter->{'encoding_name'} >>, C<< $converter->{'perl_encoding'} >>
-and C<< $converter->get_conf('documentlanguage') >> are used.
-
-C<gdt> uses a gettext-like infrastructure to retrieve the
-translated strings, using the I<texinfo_document> domain.
-
-=back
-
-The errors collected are available through the C<errors> method, the other
-methods allow registering errors and warnings.
-
-=over
+If called on a C<$converter>, the C<$converter> is initialized itself
+such as to be able to call Texinfo::Report methods. It is how it is
+used in the Converters.
=item ($error_warnings_list, $error_count) = errors ($registrar)
@@ -601,18 +319,22 @@ the error or warning.
=item $registrar->line_error($text, $configuration_informations, $line_nr)
Register a warning or an error. The I<$text> is the text of the
-error or warning. The optional I<$line_nr> holds the information
-on the error or warning location. It is associated with the I<line_nr>
-key of Texinfo tree elements as described in L<Texinfo::Parser/line_nr>
-for the @-commands. The I<$line_nr> structure is described in
L<errors|($error_warnings_list, $error_count) = errors ($registrar)>
+error or warning. The I<$configuration_informations> object gives
+some information that can modify the messages or their delivery.
+The optional I<$line_nr> holds the information on the error or
+warning location. It is associated with the I<line_nr> key of
+Texinfo tree elements as described in L<Texinfo::Parser/line_nr>
+for the @-commands. The I<$line_nr> structure is described
+in L<errors|($error_warnings_list, $error_count) = errors ($registrar)>
above.
-=item $registrar->document_warn($text)
+=item $registrar->document_warn($text, $configuration_informations)
-=item $registrar->document_error($text)
+=item $registrar->document_error($text, $configuration_informations)
Register a document-wide error or warning. I<$text> is the error or
-warning message.
+warning message. The I<$configuration_informations> object gives
+some information that can modify the messages or their delivery.
=item $registrar->file_line_warn($text, $file, $line_nr)
diff --git a/tp/Texinfo/Report.pm b/tp/Texinfo/Translations.pm
similarity index 55%
copy from tp/Texinfo/Report.pm
copy to tp/Texinfo/Translations.pm
index 0326af5..3d3c03e 100644
--- a/tp/Texinfo/Report.pm
+++ b/tp/Texinfo/Translations.pm
@@ -1,4 +1,4 @@
-# Report.pm: prepare error messages and translate strings.
+# Translations.pm: translate strings.
#
# Copyright 2010-2020 Free Software Foundation, Inc.
#
@@ -17,12 +17,13 @@
#
# Original author: Patrice Dumas <pertusus@free.fr>
+package Texinfo::Translations;
+
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter);
%EXPORT_TAGS = ( 'all' => [ qw(
- errors
gdt
) ] );
@@ -31,14 +32,9 @@ use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@EXPORT = qw(
);
-package Texinfo::Report;
-
use 5.00405;
use strict;
-# for fileparse
-use File::Basename;
-
use POSIX qw(setlocale LC_ALL);
use Locale::Messages;
# to be able to load a parser if none was given to gdt.
@@ -48,193 +44,13 @@ use Texinfo::Parser;
# strings translations so we don't use the system gettext.
Locale::Messages->select_package ('gettext_pp');
-my $messages_textdomain = 'texinfo';
-
-# this module does not use Texinfo::Common, therefore does not
-# obtain those functions, they are defined here
-sub __($) {
- my $msgid = shift;
- return Locale::Messages::dgettext($messages_textdomain, $msgid);
-}
-
-sub __p($$) {
- my $context = shift;
- my $msgid = shift;
- return Locale::Messages::dpgettext($messages_textdomain, $context, $msgid);
-}
-
-
-
-sub new(;$)
-{
- my $self = shift;
- # if there is no argument, setup a separate Texinfo::Report object,
- # otherwise the structure is added to the converter, nothing is "blessed".
- if (not defined($self)) {
- $self = {};
- bless $self;
- }
- $self->{'errors_warnings'} = [];
- #print STDERR "REPORT NEW $self $self->{'errors_warnings'}\n";
- $self->{'errors_nrs'} = 0;
- return $self;
-}
-
-# return the errors and warnings
-sub errors($)
-{
- my $self = shift;
- return ($self->{'errors_warnings'}, $self->{'error_nrs'});
-}
-
-# format a line warning
-sub line_warn($$$$)
-{
- my $self = shift;
- my $configuration_informations = shift;
- my $text = shift;
- chomp ($text);
- my $line_number = shift;
- return if (!defined($line_number));
- my $file = $line_number->{'file_name'};
- # otherwise out of source build fail since the file names are different
- my ($directories, $suffix);
- ($file, $directories, $suffix) = fileparse($file)
- if ($configuration_informations->get_conf('TEST'));
- my $warn_line;
- if ($line_number->{'macro'} ne '') {
- $warn_line = sprintf(__p("Texinfo source file warning",
- "%s:%d: warning: %s (possibly involving \@%s)\n"),
- $file, $line_number->{'line_nr'}, $text, $line_number->{'macro'});
- } else {
- $warn_line = sprintf(__p("Texinfo source file warning",
- "%s:%d: warning: %s\n"),
- $file, $line_number->{'line_nr'}, $text);
- }
- warn $warn_line if ($configuration_informations->get_conf('DEBUG'));
- push @{$self->{'errors_warnings'}},
- { 'type' => 'warning', 'text' => $text, 'error_line' => $warn_line,
- %{$line_number} };
-}
-
-# format a line error
-sub line_error($$$$)
-{
- my $self = shift;
- my $configuration_informations = shift;
- my $text = shift;
- chomp ($text);
- my $line_number = shift;
- if (defined($line_number)) {
- my $file = $line_number->{'file_name'};
- my ($directories, $suffix);
- ($file, $directories, $suffix) = fileparse($file)
- if ($configuration_informations->get_conf('TEST'));
- my $macro_text = '';
- $macro_text = " (possibly involving \@$line_number->{'macro'})"
- if ($line_number->{'macro'} ne '');
- my $error_text = "$file:$line_number->{'line_nr'}: $text$macro_text\n";
- warn "$error_text" if ($configuration_informations->get_conf('DEBUG'));
- push @{$self->{'errors_warnings'}},
- { 'type' => 'error', 'text' => $text, 'error_line' => $error_text,
- %{$line_number} };
- }
- $self->{'error_nrs'}++;
-}
-
-sub document_warn($$$)
-{
- my $self = shift;
- my $configuration_informations = shift;
- my $text = shift;
- chomp($text);
-
- my $warn_line;
- if (defined($configuration_informations->get_conf('PROGRAM'))
- and $configuration_informations->get_conf('PROGRAM') ne '') {
- $warn_line = sprintf(__p("whole document warning", "%s: warning: %s\n"),
- $configuration_informations->get_conf('PROGRAM'), $text);
- } else {
- $warn_line = sprintf(__p("whole document warning", "warning: %s\n"),
- $text);
- }
- push @{$self->{'errors_warnings'}},
- { 'type' => 'warning', 'text' => $text, 'error_line' => $warn_line };
-}
-
-sub document_error($$$)
-{
- my $self = shift;
- my $configuration_informations = shift;
- my $text = shift;
- chomp($text);
- my $error_line;
- if (defined($configuration_informations->get_conf('PROGRAM'))
- and $configuration_informations->get_conf('PROGRAM') ne '') {
- $error_line = sprintf("%s: %s\n",
- $configuration_informations->get_conf('PROGRAM'), $text);
- } else {
- $error_line = "$text\n";
- }
- push @{$self->{'errors_warnings'}},
- { 'type' => 'error', 'text' => $text, 'error_line' => $error_line };
- $self->{'error_nrs'}++;
-}
-
-sub file_line_warn($$$;$)
-{
- my $self = shift;
- my $text = shift;
- chomp($text);
- my $file = shift;
- my $line_nr = shift;
-
- my $warn_line;
- if (!defined($file)) {
- $warn_line = sprintf(__p("file warning", "warning: %s\n"), $text);
- } elsif (!defined($line_nr)) {
- $warn_line = sprintf(__p("file warning", "%s: warning: %s\n"),
- $file, $text);
- } else {
- $warn_line = sprintf(__p("file warning", "%s:%d: warning: %s\n"),
- $file, $line_nr, $text);
- }
- #print STDERR "REPORT FILE_LINE_WARN $self $self->{'errors_warnings'}\n";
- push @{$self->{'errors_warnings'}},
- { 'type' => 'warning', 'text' => $text, 'error_line' => $warn_line};
-}
-
-sub file_line_error($$$;$)
-{
- my $self = shift;
- my $text = shift;
- chomp($text);
- my $file = shift;
- my $line_nr = shift;
-
- my $error_line;
- if (!defined($file)) {
- $error_line = "$text\n";
- } elsif (!defined($line_nr)) {
- $error_line = "$file: $text\n";
- } else {
- $error_line = "$file:$line_nr: $text\n";
- }
- #print STDERR "REPORT FILE_LINE_WARN $self $self->{'errors_warnings'}\n";
- push @{$self->{'errors_warnings'}},
- { 'type' => 'error', 'text' => $text, 'error_line' => $error_line};
- $self->{'error_nrs'}++;
-}
-
-
# i18n
my $DEFAULT_LANGUAGE = 'en';
-
+my $messages_textdomain = 'texinfo';
my $strings_textdomain = 'texinfo_document';
-
# libintl converts between encodings but doesn't decode them into the
# perl internal format. This is only called if the encoding is a proper
# perl encoding.
@@ -460,23 +276,11 @@ __END__
=head1 NAME
-Texinfo::Report - Error storing and string translations for Texinfo modules
+Texinfo::Translations - Translations of output documents strings for Texinfo
modules
=head1 SYNOPSIS
- @ISA = qw(Texinfo::Report);
-
- $registrar->Texinfo::Report::new();
-
- if ($warning_happened) {
- $registrar->line_warn($converter, sprintf(__("\@%s is wrongly used"),
- $current->{'cmdname'}), $current->{'line_nr'});
- }
-
- my ($errors, $errors_count) = $registrar->errors();
- foreach my $error_message (@$errors) {
- warn $error_message->{'error_line'};
- }
+ @ISA = qw(Texinfo::Translations);
my $tree_translated = $converter->gdt('See {reference} in @cite{{book}}',
{'reference' => $tree_reference,
@@ -485,23 +289,17 @@ Texinfo::Report - Error storing and string translations
for Texinfo modules
=head1 DESCRIPTION
-The Texinfo::Report module helps with string translations and error
-handling. It is used by the Texinfo modules Texinfo::Parser and
-Texinfo::Convert::Converter. To use this module, initialize the
-Texinfo::Report object with C<Texinfo::Report::new()>.
+The Texinfo::Translations module helps with string translations
+in output documents.
-Besides the C<new> method, C<gdt> is used for string translations,
-C<errors> for reporting errors, and the other methods to store errors
-(and warnings).
+Translation of error messages uses another interface which
+is the classical gettext based perl interface. It is not
+described as it is described in details elsewhere.
=head1 METHODS
No method is exported in the default case.
-The C<new> method initializes Texinfo::Report related fields:
-
- $converter->Texinfo::Report::new()
-
The C<gdt> method is used to translate strings to be output in
converted documents, and return a texinfo tree.
@@ -554,78 +352,6 @@ translated strings, using the I<texinfo_document> domain.
=back
-The errors collected are available through the C<errors> method, the other
-methods allow registering errors and warnings.
-
-=over
-
-=item ($error_warnings_list, $error_count) = errors ($registrar)
-
-This function returns as I<$error_count> the count of errors since
-calling C<new>. The I<$error_warnings_list> is an array of hash references
-one for each error, warning or error line continuation. Each of these has
-the following keys:
-
-=over
-
-=item type
-
-May be C<warning>, or C<error>.
-
-=item text
-
-The text of the error.
-
-=item error_line
-
-The text of the error formatted with the file name, line number and macro
-name, as needed.
-
-=item line_nr
-
-The line number of the error or warning.
-
-=item file_name
-
-The file name where the error or warning occurs.
-
-=item macro
-
-The user macro name that is expanded at the location of
-the error or warning.
-
-=back
-
-=item $registrar->line_warn($text, $configuration_informations, $line_nr)
-
-=item $registrar->line_error($text, $configuration_informations, $line_nr)
-
-Register a warning or an error. The I<$text> is the text of the
-error or warning. The optional I<$line_nr> holds the information
-on the error or warning location. It is associated with the I<line_nr>
-key of Texinfo tree elements as described in L<Texinfo::Parser/line_nr>
-for the @-commands. The I<$line_nr> structure is described in
L<errors|($error_warnings_list, $error_count) = errors ($registrar)>
-above.
-
-=item $registrar->document_warn($text)
-
-=item $registrar->document_error($text)
-
-Register a document-wide error or warning. I<$text> is the error or
-warning message.
-
-=item $registrar->file_line_warn($text, $file, $line_nr)
-
-Register the warning message I<$text> for file I<$file>, with, optionally
-the line I<$line_nr> in the file.
-
-=item $registrar->file_line_error($text, $file, $line_nr)
-
-Register the error message I<$text> for file I<$file>, with, optionally
-the line I<$line_nr> in the file.
-
-=back
-
=head1 AUTHOR
Patrice Dumas, E<lt>pertusus@free.frE<gt>
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index a1ba70e..83a02fc 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -27,8 +27,9 @@ use Texinfo::Common;
use Texinfo::Encoding;
use Texinfo::Convert::NodeNameNormalization;
use Texinfo::Report;
+use Texinfo::Translations;
-our @ISA = qw(Exporter Texinfo::Report);
+our @ISA = qw(Exporter Texinfo::Translations);
our %EXPORT_TAGS = ( 'all' => [ qw(
parser
parse_texi_text
@@ -83,7 +84,7 @@ sub parser (;$$)
add_include_directory ($d);
}
} elsif ($key eq 'values') {
- # This is used by Texinfo::Report::gdt for substituted values
+ # This is used by Texinfo::Translations::gdt for substituted values
for my $v (keys %{$conf->{'values'}}) {
if (!ref($conf->{'values'}->{$v})) {
store_value ($v, $conf->{'values'}->{$v});
diff --git a/tp/t/automatic_nodes.t b/tp/t/automatic_nodes.t
index 40c24a6..065e18c 100644
--- a/tp/t/automatic_nodes.t
+++ b/tp/t/automatic_nodes.t
@@ -24,10 +24,11 @@ sub test_new_node($$$$)
my $parser = Texinfo::Parser::parser();
my $line = $parser->parse_texi_line ($in);
+ my $registrar = $parser->registered_errors();
my ($labels, $targets_list, $nodes_list) = $parser->labels_information();
my $parser_informations = $parser->global_informations();
my $refs = $parser->internal_references_information();
- Texinfo::Structuring::associate_internal_references($parser, $parser,
+ Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
# $labels, $nodes_list, $targets_list are modified
my $node = Texinfo::Transformations::_new_node($parser, $line,
@@ -37,7 +38,7 @@ sub test_new_node($$$$)
if (defined($node)) {
$texi_result = Texinfo::Convert::Texinfo::convert_to_texinfo($node);
my $refs = $parser->internal_references_information();
- Texinfo::Structuring::associate_internal_references($parser, $parser,
+ Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
$normalized = $node->{'extra'}->{'normalized'};
my @labels = sort(keys(%$labels));
@@ -77,10 +78,11 @@ my $parser = Texinfo::Parser::parser();
my $tree = $parser->parse_texi_text('@node a node
');
my $line_tree = Texinfo::Parser::parse_texi_line (undef, 'a node');
+my $registrar = $parser->registered_errors();
my ($labels, $targets_list, $nodes_list) = $parser->labels_information();
my $parser_informations = $parser->global_informations();
my $refs = $parser->internal_references_information();
-Texinfo::Structuring::associate_internal_references($parser, $parser,
+Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
my $node = Texinfo::Transformations::_new_node($parser, $line_tree,
$nodes_list, $targets_list, $labels);
@@ -153,10 +155,11 @@ Text.
$parser = Texinfo::Parser::parser();
$tree = $parser->parse_texi_text ($sections_text);
+ $registrar = $parser->registered_errors();
($labels, $targets_list, $nodes_list) = $parser->labels_information();
$parser_informations = $parser->global_informations();
$refs = $parser->internal_references_information();
- Texinfo::Structuring::associate_internal_references($parser, $parser,
+ Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
my ($new_content, $added_nodes)
= Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser,
@@ -178,10 +181,11 @@ $tree = $parser->parse_texi_text ('@node Top
* (some_manual)::
@end menu
');
+$registrar = $parser->registered_errors();
($labels, $targets_list, $nodes_list) = $parser->labels_information();
$parser_informations = $parser->global_informations();
$refs = $parser->internal_references_information();
-Texinfo::Structuring::associate_internal_references($parser, $parser,
+Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
($new_content, $added_nodes)
= Texinfo::Transformations::insert_nodes_for_sectioning_commands($parser,
diff --git a/tp/t/do_master_menu.t b/tp/t/do_master_menu.t
index ba3bcd7..9862949 100644
--- a/tp/t/do_master_menu.t
+++ b/tp/t/do_master_menu.t
@@ -123,10 +123,11 @@ my $no_detailmenu = _get_in('');
my $parser = Texinfo::Parser::parser();
my $tree = $parser->parse_texi_text($in_detailmenu);
+my $registrar = $parser->registered_errors();
my ($labels, $targets_list, $nodes_list) = $parser->labels_information();
my $parser_informations = $parser->global_informations();
my $refs = $parser->internal_references_information();
-Texinfo::Structuring::associate_internal_references($parser, $parser,
+Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
my $master_menu = Texinfo::Transformations::new_master_menu($parser, $labels);
my $out = Texinfo::Convert::Texinfo::convert_to_texinfo($master_menu);
@@ -167,10 +168,11 @@ is ($out, $reference, 'master menu');
$parser = Texinfo::Parser::parser();
$tree = $parser->parse_texi_text($no_detailmenu);
+$registrar = $parser->registered_errors();
($labels, $targets_list, $nodes_list) = $parser->labels_information();
$parser_informations = $parser->global_informations();
$refs = $parser->internal_references_information();
-Texinfo::Structuring::associate_internal_references($parser, $parser,
+Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
$master_menu = Texinfo::Transformations::new_master_menu($parser, $labels);
$out = Texinfo::Convert::Texinfo::convert_to_texinfo($master_menu);
@@ -178,10 +180,11 @@ is ($out, $reference, 'master menu no detailmenu');
$parser = Texinfo::Parser::parser();
$tree = $parser->parse_texi_text($in_detailmenu);
+$registrar = $parser->registered_errors();
($labels, $targets_list, $nodes_list) = $parser->labels_information();
$parser_informations = $parser->global_informations();
$refs = $parser->internal_references_information();
-Texinfo::Structuring::associate_internal_references($parser, $parser,
+Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
Texinfo::Transformations::regenerate_master_menu($parser, $labels);
$out = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
@@ -192,10 +195,11 @@ is ($out, _get_in($reference), 'regenerate with existing
detailmenu');
$parser = Texinfo::Parser::parser();
$tree = $parser->parse_texi_text($no_detailmenu);
+$registrar = $parser->registered_errors();
($labels, $targets_list, $nodes_list) = $parser->labels_information();
$parser_informations = $parser->global_informations();
$refs = $parser->internal_references_information();
-Texinfo::Structuring::associate_internal_references($parser, $parser,
+Texinfo::Structuring::associate_internal_references($registrar, $parser,
$parser_informations, $labels, $refs);
Texinfo::Transformations::regenerate_master_menu($parser, $labels);
$out = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 6bbc687..2965393 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -654,6 +654,7 @@ sub handle_errors($$$)
my $self = shift;
my $error_count = shift;
my $opened_files = shift;
+
my ($errors, $new_error_count) = $self->errors();
$error_count += $new_error_count if ($new_error_count);
foreach my $error_message (@$errors) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Report.pm, tp/Texinfo/Translations.pm, tp/Texinfo/Convert/Converter.pm, tp/Texinfo/Convert/Text.pm, tp/Texinfo/ParserNonXS.pm, tp/Texinfo/XS/parsetexi/Parsetexi.pm: move gdt() and string translation related code from tp/Texinfo/Report.pm to newly created tp/Texinfo/Translations.pm.,
Patrice Dumas <=