texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/Converter.pm (pcdt): call cd


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Converter.pm (pcdt): call cdt.
Date: Fri, 02 Feb 2024 13:53:01 -0500

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 d3c4a9b7ea * tp/Texinfo/Convert/Converter.pm (pcdt): call cdt.
d3c4a9b7ea is described below

commit d3c4a9b7ea5def6fa7897ee499022fa6b61636a8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Feb 2 19:52:53 2024 +0100

    * tp/Texinfo/Convert/Converter.pm (pcdt): call cdt.
    
    * tp/Texinfo/Translations.pm (gdt, gdt_string): add a
    $translate_string_method to allow customization of translate_string
    instead of using can on the $customization_information argument.
    
    * tp/Texinfo/Convert/HTML.pm (@ISA, html_translate_string)
    (cdt, cdt_string): do not inherit Texinfo::Translations.
    Rename translate_string as html_translate_string.  Redefine cdt and
    cdt_string to pass html_translate_string to gdt and gdt_string
    to customize translate_string.
---
 ChangeLog                       | 14 ++++++++++++
 tp/Texinfo/Convert/Converter.pm |  4 +---
 tp/Texinfo/Convert/HTML.pm      | 31 +++++++++++++++++++++++---
 tp/Texinfo/Translations.pm      | 48 ++++++++++++++++++-----------------------
 4 files changed, 64 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 27bcb2ef4e..35a16c4cdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-02-02  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Converter.pm (pcdt): call cdt.
+
+       * tp/Texinfo/Translations.pm (gdt, gdt_string): add a
+       $translate_string_method to allow customization of translate_string
+       instead of using can on the $customization_information argument.
+
+       * tp/Texinfo/Convert/HTML.pm (@ISA, html_translate_string)
+       (cdt, cdt_string): do not inherit Texinfo::Translations.
+       Rename translate_string as html_translate_string.  Redefine cdt and
+       cdt_string to pass html_translate_string to gdt and gdt_string
+       to customize translate_string.
+
 2024-02-02  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/convert_utils.c (cdt_tree): add to replace
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index cdbd9734b2..59605f6d31 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -650,9 +650,7 @@ sub pcdt($$;$$)
 {
   my ($self, $translation_context, $string, $replaced_substrings) = @_;
 
-  return Texinfo::Translations::pgdt($self, $translation_context, $string,
-                                     $self->get_conf('documentlanguage'),
-                                     $replaced_substrings);
+  return $self->cdt($string, $replaced_substrings, $translation_context);
 }
 
 sub converter_line_error($$$;$)
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 45f3092da2..1210a90d08 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -86,7 +86,7 @@ use Texinfo::Convert::LaTeX;
 
 require Exporter;
 use vars qw($VERSION @ISA);
-@ISA = qw(Texinfo::Convert::Converter Texinfo::Translations);
+@ISA = qw(Texinfo::Convert::Converter);
 
 $VERSION = '7.1dev';
 
@@ -2842,7 +2842,7 @@ sub _translate_names($)
 # redefined functions
 #
 # Texinfo::Translations::translate_string redefined to call user defined 
function.
-sub translate_string($$;$$)
+sub html_translate_string($$;$$)
 {
   my ($self, $string, $lang, $translation_context) = @_;
   if (defined($self->{'formatting_function'}->{'format_translate_message'})) {
@@ -2857,7 +2857,32 @@ sub translate_string($$;$$)
     }
   }
 
-  return $self->SUPER::translate_string($string, $lang, $translation_context);
+  return Texinfo::Translations::translate_string($self, $string, $lang,
+                                                 $translation_context);
+}
+
+# redefine generic Converter functions to pass a customized translate_string
+# function
+sub cdt($$;$$)
+{
+  my ($self, $string, $replaced_substrings, $translation_context) = @_;
+
+  return Texinfo::Translations::gdt($self, $string,
+                                    $self->get_conf('documentlanguage'),
+                                    $replaced_substrings,
+                                    $translation_context,
+                                    \&html_translate_string);
+}
+
+sub cdt_string($$;$$)
+{
+  my ($self, $string, $replaced_substrings, $translation_context) = @_;
+
+  return Texinfo::Translations::gdt_string($self, $string,
+                                    $self->get_conf('documentlanguage'),
+                                    $replaced_substrings,
+                                    $translation_context,
+                                    \&html_translate_string);
 }
 
 sub converter_defaults($$)
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index a7004aa1b6..e9af5a2f16 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -150,12 +150,11 @@ sub _switch_messages_locale
 sub translate_string($$;$$)
 {
   my ($customization_information, $string, $lang, $translation_context) = @_;
-  if (ref($customization_information) eq 'Texinfo::Document') {
-    cluck;
-  }
+
   if (defined($lang) and $lang eq '') {
     cluck ("BUG: defined but empty documentlanguage: 
$customization_information: '$string'\n");
   }
+
   $lang = $DEFAULT_LANGUAGE if (!defined($lang));
 
   my ($saved_LC_MESSAGES, $saved_LANGUAGE);
@@ -229,18 +228,15 @@ sub translate_string($$;$$)
 
 # Get document translation - handle translations of in-document strings.
 # Return a parsed Texinfo tree
-sub gdt($$;$$$)
+sub gdt($$;$$$$)
 {
   my ($customization_information, $string, $lang, $replaced_substrings,
-      $translation_context) = @_;
-
-  # allows to redefine translate_string, as done in the HTML converter.  Cannot
-  # directly call translate_string on $customization_information, as it may not
-  # provide the method if it does not inherit from Texinfo::Translations, as is
-  # the case for most $customization_information objects.
-  my $translate_string_method
-     = $customization_information->can('translate_string');
-  $translate_string_method = \&translate_string if (!$translate_string_method);
+      $translation_context, $translate_string_method) = @_;
+
+  if (!$translate_string_method) {
+    $translate_string_method = \&translate_string;
+  }
+
   my $translated_string = &$translate_string_method($customization_information,
                                        $string, $lang, $translation_context);
 
@@ -255,20 +251,14 @@ sub gdt($$;$$$)
 # Get document translation - handle translations of in-document strings.
 # In general for already converted strings that do not need to go through
 # a Texinfo tree.
-sub gdt_string($$;$$$)
+sub gdt_string($$;$$$$)
 {
   my ($customization_information, $string, $lang, $replaced_substrings,
-      $translation_context) = @_;
-
-  # Following code allows to redefine translate_string, as done in the HTML
-  # converter.  We check with can() explicitely instead of letting inheritance
-  # rules determine which method to call (which would be achieved with
-  # $customization_information->translate_string) because
-  # $customization_information may not provide the method if it does not
-  # inherit from Texinfo::Translations, as is the case for Texinfo::Parser.
-  my $translate_string_method
-     = $customization_information->can('translate_string');
-  $translate_string_method = \&translate_string if (!$translate_string_method);
+      $translation_context, $translate_string_method) = @_;
+
+  if (!$translate_string_method) {
+    $translate_string_method = \&translate_string;
+  }
 
   my $translated_string = &$translate_string_method($customization_information,
                                        $string, $lang, $translation_context);
@@ -555,9 +545,9 @@ but returns a simple string, for already converted strings.
 
 =over
 
-=item $tree = $object->gdt($string, $lang, $replaced_substrings, 
$translation_context)
+=item $tree = $object->gdt($string, $lang, $replaced_substrings, 
$translation_context, $translate_string_method)
 
-=item $string = $object->gdt_string($string, $lang, $replaced_substrings, 
$translation_context)
+=item $string = $object->gdt_string($string, $lang, $replaced_substrings, 
$translation_context, $translate_string_method)
 
 X<C<gdt>> X<C<gdt_string>>
 
@@ -585,6 +575,10 @@ The I<$translation_context> is optional.  If not C<undef> 
this is a translation
 context string for I<$string>.  It is the first argument of C<pgettext>
 in the C API of Gettext.
 
+The I<$translate_string_method> is optional.  If not undef it should be a
+reference on a function that is called instead of C<translate_string>.  It
+allows to customize string translation.
+
 For example, in the following call, the string
 C<See {reference} in @cite{{book}}> is translated, then
 parsed as a Texinfo string, with I<{reference}> substituted by



reply via email to

[Prev in Thread] Current Thread [Next in Thread]