texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Translations.pm (gdt_string_columns)


From: Gavin D. Smith
Subject: branch master updated: * tp/Texinfo/Translations.pm (gdt_string_columns): Adjust to only count width of text that comes from the translated string, itself, not counting substituted text. * tp/Texinfo/Convert/Plaintext.pm (_text_heading): Count width of heading in three parts: the heading, the number, and additional text returned from gdt_string_columns.
Date: Sun, 31 Dec 2023 15:19:31 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 25d4c4c6ed * tp/Texinfo/Translations.pm (gdt_string_columns): Adjust 
to only count width of text that comes from the translated string, itself, not 
counting substituted text. * tp/Texinfo/Convert/Plaintext.pm (_text_heading): 
Count width of heading in three parts: the heading, the number, and additional 
text returned from gdt_string_columns.
25d4c4c6ed is described below

commit 25d4c4c6ed1e5b23cf30965c3ea102fc4aee8cab
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Dec 31 20:17:38 2023 +0000

    * tp/Texinfo/Translations.pm (gdt_string_columns): Adjust to
    only count width of text that comes from the translated string,
    itself, not counting substituted text.
    * tp/Texinfo/Convert/Plaintext.pm (_text_heading):
    Count width of heading in three parts: the heading, the number,
    and additional text returned from gdt_string_columns.
    
    No functional changes intended.
---
 ChangeLog                       | 11 +++++++++++
 tp/Texinfo/Convert/Plaintext.pm | 14 ++++++++++----
 tp/Texinfo/Translations.pm      | 30 ++++++++++++++++++++++++++----
 3 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0d9680476e..345f8b2513 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-12-31  Gavin Smith <gavinsmith0123@gmail.com>
+
+       * tp/Texinfo/Translations.pm (gdt_string_columns): Adjust to
+       only count width of text that comes from the translated string,
+       itself, not counting substituted text.
+       * tp/Texinfo/Convert/Plaintext.pm (_text_heading):
+       Count width of heading in three parts: the heading, the number,
+       and additional text returned from gdt_string_columns.
+
+       No functional changes intended.
+
 2023-12-31  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_convert_multitable_command)
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 5f53d99ac7..b747cc8ff0 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -1714,22 +1714,28 @@ sub _text_heading($$$;$$)
   my $heading = $self->convert_line_new_context (
                          {'type' => 'frenchspacing',
                           'contents' => [$heading_element]});
-  my ($text, $columns);
+
+  my $heading_width = Texinfo::Convert::Unicode::string_width($heading);
+
+  my ($text, $number_width, $gdt_width);
   if (defined($number)) {
+    $number_width = length($number);
     if ($current->{'cmdname'} eq 'appendix'
         and $current->{'extra'}->{'section_level'} == 1) {
-      ($text, $columns) = $self->gdt_string_columns(
+      ($text, $gdt_width) = $self->gdt_string_columns(
                  'Appendix {number} {section_title}',
                  {'number' => $number, 'section_title' => $heading});
     } else {
-      ($text, $columns) = $self->gdt_string_columns(
+      ($text, $gdt_width) = $self->gdt_string_columns(
                  '{number} {section_title}',
                  {'number' => $number, 'section_title' => $heading});
     }
   } else {
     $text = $heading;
-    $columns = Texinfo::Convert::Unicode::string_width($heading);
+    $number_width = 0;
+    $gdt_width = 0;
   }
+  my $columns = $heading_width + $number_width + $gdt_width;
 
   return '' if ($text !~ /\S/);
   my $result = $text ."\n";
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index 4961da2435..8e3d9ed679 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -329,6 +329,7 @@ sub gdt_string($$;$$$)
   # $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.
+  # (Same is done in gdt_string_columns.)
   my $translate_string_method
      = $customization_information->can('translate_string');
   $translate_string_method = \&translate_string if (!$translate_string_method);
@@ -341,7 +342,8 @@ sub gdt_string($$;$$$)
 }
 
 # Like gdt_string, but additionally return the width of the result in
-# screen columns.
+# screen columns, not counting the width of substituted strings.
+#
 # TODO: In the future, this function may return an encoded string, and
 # take encoded arguments.  The plan is to save the width in columns before
 # encoding the string.
@@ -350,9 +352,29 @@ sub gdt_string_columns($$;$$$)
   my ($customization_information, $string, $replaced_substrings,
       $translation_context, $lang) = @_;
 
-  my $result = gdt_string($customization_information, $string,
-                          $replaced_substrings, $translation_context, $lang);
-  return ($result, Texinfo::Convert::Unicode::string_width($result));
+  # see comment in gdt_string
+  my $translate_string_method
+     = $customization_information->can('translate_string');
+  $translate_string_method = \&translate_string if (!$translate_string_method);
+
+  my $translated_string = &$translate_string_method($customization_information,
+                                       $string, $translation_context, $lang);
+
+  my ($result, $result_counted) = ($translated_string, $translated_string);
+
+  my $re;
+  if (defined($replaced_substrings) and ref($replaced_substrings)) {
+    $re = join '|', map { quotemeta $_ } keys %$replaced_substrings;
+
+    # Replace placeholders
+    $result =~
+      s/\{($re)\}/defined $replaced_substrings->{$1} ? 
$replaced_substrings->{$1} : "{$1}"/ge;
+
+    # Strip out placeholders
+    $result_counted =~ s/\{($re)\}//g;
+  }
+
+  return ($result, Texinfo::Convert::Unicode::string_width($result_counted));
 }
 
 sub replace_substrings($$;$)



reply via email to

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