texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Thu, 12 Oct 2023 17:11:08 -0400 (EDT)

branch: master
commit 346033271466bf900e692b203d1f228d57998342
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Oct 12 22:59:09 2023 +0200

    Add definition aliases translation context in the tree if needed
    
    * tp/Texinfo/Common.pm (pgdt_context, %def_map),
    tp/Texinfo/ParserNonXS.pm (_parse_def), tp/Texinfo/XS/parsetexi/def.c
    (DEF_ALIAS, def_aliases, parse_def): add pgdt_context to mark strings,
    which returns the context too.  Use the context in _parse_def to
    add it to the tree for untranslated type.  Similarly in def_aliases in
    def.c add a translation context if needed and add it to the tree in
    parse_def.
    
    * po_document/Makevars (XGETTEXT_OPTIONS): add pgdt_context.
---
 ChangeLog                                          | 14 +++++++++++
 po_document/Makevars                               |  3 ++-
 tp/Texinfo/Common.pm                               | 24 ++++++++++++-------
 tp/Texinfo/ParserNonXS.pm                          | 25 ++++++++++++++++---
 tp/Texinfo/XS/parsetexi/def.c                      | 28 ++++++++++++----------
 tp/t/results/languages/documentlanguage.pl         |  3 ++-
 tp/t/results/languages/documentlanguage_option.pl  |  3 ++-
 tp/t/results/languages/documentlanguage_unknown.pl |  3 ++-
 .../results/languages/multiple_documentlanguage.pl |  9 ++++---
 tp/t/results/languages/multiple_in_preamble.pl     |  9 ++++---
 .../languages/multiple_in_preamble_before_node.pl  |  6 +++--
 tp/t/results/languages/multiple_lang_chapters.pl   |  9 ++++---
 .../languages/multiple_lang_chapters_latex.pl      |  9 ++++---
 .../languages/multiple_lang_chapters_texi2html.pl  |  9 ++++---
 tp/t/results/languages/simple_documentlanguage.pl  |  3 ++-
 tp/t/results/languages/unknown_region.pl           |  3 ++-
 16 files changed, 114 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e9118f8404..cdb1c038e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-10-12  Patrice Dumas <pertusus@free.fr>
+
+       Add definition aliases translation context in the tree if needed
+
+       * tp/Texinfo/Common.pm (pgdt_context, %def_map),
+       tp/Texinfo/ParserNonXS.pm (_parse_def), tp/Texinfo/XS/parsetexi/def.c
+       (DEF_ALIAS, def_aliases, parse_def): add pgdt_context to mark strings,
+       which returns the context too.  Use the context in _parse_def to
+       add it to the tree for untranslated type.  Similarly in def_aliases in
+       def.c add a translation context if needed and add it to the tree in
+       parse_def.
+
+       * po_document/Makevars (XGETTEXT_OPTIONS): add pgdt_context.
+
 2023-10-12  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/maintain/regenerate_docstr.sh: Correct path to Makefile.am.
diff --git a/po_document/Makevars b/po_document/Makevars
index f8d993ad23..c1ce7264fe 100644
--- a/po_document/Makevars
+++ b/po_document/Makevars
@@ -9,7 +9,8 @@ top_builddir = ..
 
 # These options get passed to xgettext.
 XGETTEXT_OPTIONS = -cTRANSLATORS --language=Perl \
-  --keyword=gdt --keyword=pgdt:1c,2 --from-code=UTF-8
+  --keyword=gdt --keyword=pgdt:1c,2 --keyword=pgdt_context:1c,2 \
+  --from-code=UTF-8
 
 # This is the copyright holder that gets inserted into the header of the
 # $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index e2a989806a..c527567ade 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -108,6 +108,12 @@ sub pgdt($$)
   return $_[1];
 }
 
+# to be used when the context needs to be returned too
+sub pgdt_context($$)
+{
+  return [$_[0], $_[1]];
+}
+
 
 # determine the null devices
 my $default_null_device = File::Spec->devnull();
@@ -627,32 +633,34 @@ our %def_map = (
     # shortcuts
     # The strings are marked to be translated in the parsers with type
     # 'untranslated'.
-    'defun',         {'deffn'     => pgdt('category of functions for @defun',
+    'defun',         {'deffn'     => pgdt_context(
+                                         'category of functions for @defun',
                                          'Function')},
     # TRANSLATORS: category of macros for @defmac
     'defmac',        {'deffn'     => gdt('Macro')},
     # TRANSLATORS: category of special forms for @defspec
     'defspec',       {'deffn'     => gdt('Special Form')},
-    'defvar',        {'defvr'     => pgdt('category of variables for @defvar',
+    'defvar',        {'defvr'     => pgdt_context(
+                                         'category of variables for @defvar',
                                           'Variable')},
     # TRANSLATORS: category of user-modifiable options for @defopt
     'defopt',        {'defvr'     => gdt('User Option')},
-    'deftypefun',    {'deftypefn' => pgdt(
+    'deftypefun',    {'deftypefn' => pgdt_context(
                       'category of functions for @deftypefun',
                                          'Function')},
-    'deftypevar',    {'deftypevr' => pgdt(
+    'deftypevar',    {'deftypevr' => pgdt_context(
                      'category of variables in typed languages for 
@deftypevar',
                                          'Variable')},
-    'defivar',       {'defcv'     => pgdt(
+    'defivar',       {'defcv'     => pgdt_context(
       'category of instance variables in object-oriented programming for 
@defivar',
                                           'Instance Variable')},
-    'deftypeivar',   {'deftypecv' => pgdt(
+    'deftypeivar',   {'deftypecv' => pgdt_context(
       'category of instance variables with data type in object-oriented 
programming for @deftypeivar',
                                           'Instance Variable')},
-    'defmethod',     {'defop'     => pgdt(
+    'defmethod',     {'defop'     => pgdt_context(
        'category of methods in object-oriented programming for @defmethod',
                                          'Method')},
-    'deftypemethod', {'deftypeop' => pgdt(
+    'deftypemethod', {'deftypeop' => pgdt_context(
         'category of methods with data type in object-oriented programming for 
@deftypemethod',
                                          'Method')},
 );
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 2840c30e79..f389d1048a 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -3252,15 +3252,27 @@ sub _parse_def($$$$)
     # could have used def_aliases, but use code more similar with the XS parser
     if ($def_alias_commands{$command}) {
       my $real_command = $def_aliases{$command};
-      my $prepended = $def_map{$command}->{$real_command};
+      my $category;
+      my $translation_context;
+      my $category_translation_context = $def_map{$command}->{$real_command};
+      # if the translation requires a context, $category_translation_context
+      # is an array reference, otherwise it is a string.
+      if (ref($category_translation_context) eq '') {
+        $category = $category_translation_context;
+      } else {
+        ($translation_context, $category) = @$category_translation_context;
+      }
       my $bracketed = { 'type' => 'bracketed_inserted',
                         'parent' => $current };
-      my $content = { 'text' => $prepended, 'parent' => $bracketed };
-      # the prepended string is an english string (such as Function).  If
+      my $content = { 'text' => $category, 'parent' => $bracketed };
+      # the category string is an english string (such as Function).  If
       # documentlanguage is set it needs to be translated during the 
conversion.
       if (defined($self->{'documentlanguage'})) {
         $content->{'type'} = 'untranslated';
         $content->{'extra'} = {'documentlanguage' => 
$self->{'documentlanguage'}};
+        if (defined($translation_context)) {
+          $content->{'extra'}->{'translation_context'} = $translation_context;
+        }
       }
       @{$bracketed->{'contents'}} = ($content);
 
@@ -9015,6 +9027,8 @@ I<spaces> or I<delimiter>, depending on the definition.
 The I<def_index_element> is a Texinfo tree element corresponding to
 the index entry associated to the definition line, based on the
 name and class.  If needed this element is based on translated strings.
+In that case, if C<@documentlanguage> is defined where the C<def_line>
+is located, I<documentlanguage> holds the documentlanguage value.
 I<def_index_ref_element> is similar, but not translated, and only set if
 there could have been a translation.
 
@@ -9179,6 +9193,11 @@ The part preceding the command is in I<associated_part>.
 If the level of the document was modified by C<@raisections>
 or C<@lowersections>, the differential level is in I<sections_level>.
 
+=item C<untranslated>
+
+I<documentlanguage> holds the C<@documentlanguage> value.
+If there is a translation context, it should be in I<translation_context>.
+
 =back
 
 =head1 SEE ALSO
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index 6f8b68a6b9..0dc8a4f21e 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -127,21 +127,22 @@ typedef struct {
     enum command_id alias;
     enum command_id command;
     char *category;
+    char *translation_context;
 } DEF_ALIAS;
 
 DEF_ALIAS def_aliases[] = {
-  CM_defun, CM_deffn, "Function",
-  CM_defmac, CM_deffn, "Macro",
-  CM_defspec, CM_deffn, "Special Form",
-  CM_defvar, CM_defvr, "Variable",
-  CM_defopt, CM_defvr, "User Option",
-  CM_deftypefun, CM_deftypefn, "Function",
-  CM_deftypevar, CM_deftypevr, "Variable",
-  CM_defivar, CM_defcv, "Instance Variable",
-  CM_deftypeivar, CM_deftypecv, "Instance Variable",
-  CM_defmethod, CM_defop, "Method",
-  CM_deftypemethod, CM_deftypeop, "Method",
-  0, 0, 0
+  CM_defun, CM_deffn, "Function", "category of functions for @defun",
+  CM_defmac, CM_deffn, "Macro", 0,
+  CM_defspec, CM_deffn, "Special Form", 0,
+  CM_defvar, CM_defvr, "Variable", "category of variables for @defvar",
+  CM_defopt, CM_defvr, "User Option", 0,
+  CM_deftypefun, CM_deftypefn, "Function", "category of functions for 
@deftypefun",
+  CM_deftypevar, CM_deftypevr, "Variable", "category of variables in typed 
languages for @deftypevar",
+  CM_defivar, CM_defcv, "Instance Variable", "category of instance variables 
in object-oriented programming for @defivar",
+  CM_deftypeivar, CM_deftypecv, "Instance Variable", "category of instance 
variables with data type in object-oriented programming for @deftypeivar",
+  CM_defmethod, CM_defop, "Method", "category of methods in object-oriented 
programming for @defmethod",
+  CM_deftypemethod, CM_deftypeop, "Method", "category of methods with data 
type in object-oriented programming for @deftypemethod",
+  0, 0, 0, 0
 };
 
 typedef struct {
@@ -362,6 +363,9 @@ parse_def (enum command_id command, ELEMENT *current)
           e1->type = ET_untranslated;
           add_extra_string_dup (e1, "documentlanguage",
                                 global_documentlanguage);
+          if (def_aliases[i].translation_context)
+            add_extra_string_dup (e1, "translation_context",
+                                  def_aliases[i].translation_context);
         }
 
       e = new_element (ET_spaces_inserted);
diff --git a/tp/t/results/languages/documentlanguage.pl 
b/tp/t/results/languages/documentlanguage.pl
index 4d1a79e4ac..b4ac4efd35 100644
--- a/tp/t/results/languages/documentlanguage.pl
+++ b/tp/t/results/languages/documentlanguage.pl
@@ -429,7 +429,8 @@ $result_trees{'documentlanguage'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'pt'
+                            'documentlanguage' => 'pt',
+                            'translation_context' => 'category of methods with 
data type in object-oriented programming for @deftypemethod'
                           },
                           'text' => 'Method',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/documentlanguage_option.pl 
b/tp/t/results/languages/documentlanguage_option.pl
index 6ed21dcb93..e636e58e72 100644
--- a/tp/t/results/languages/documentlanguage_option.pl
+++ b/tp/t/results/languages/documentlanguage_option.pl
@@ -429,7 +429,8 @@ $result_trees{'documentlanguage_option'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr'
+                            'documentlanguage' => 'fr',
+                            'translation_context' => 'category of methods with 
data type in object-oriented programming for @deftypemethod'
                           },
                           'text' => 'Method',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/documentlanguage_unknown.pl 
b/tp/t/results/languages/documentlanguage_unknown.pl
index 4d4d2b8811..8d5ec02742 100644
--- a/tp/t/results/languages/documentlanguage_unknown.pl
+++ b/tp/t/results/languages/documentlanguage_unknown.pl
@@ -429,7 +429,8 @@ $result_trees{'documentlanguage_unknown'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'unknown'
+                            'documentlanguage' => 'unknown',
+                            'translation_context' => 'category of methods with 
data type in object-oriented programming for @deftypemethod'
                           },
                           'text' => 'Method',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/multiple_documentlanguage.pl 
b/tp/t/results/languages/multiple_documentlanguage.pl
index ef61d00d5a..2a3a9be996 100644
--- a/tp/t/results/languages/multiple_documentlanguage.pl
+++ b/tp/t/results/languages/multiple_documentlanguage.pl
@@ -73,7 +73,8 @@ $result_trees{'multiple_documentlanguage'} = {
                               'contents' => [
                                 {
                                   'extra' => {
-                                    'documentlanguage' => 'fr'
+                                    'documentlanguage' => 'fr',
+                                    'translation_context' => 'category of 
instance variables in object-oriented programming for @defivar'
                                   },
                                   'text' => 'Instance Variable',
                                   'type' => 'untranslated'
@@ -426,7 +427,8 @@ $result_trees{'multiple_documentlanguage'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr'
+                            'documentlanguage' => 'fr',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -702,7 +704,8 @@ $result_trees{'multiple_documentlanguage'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'hr'
+                            'documentlanguage' => 'hr',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/multiple_in_preamble.pl 
b/tp/t/results/languages/multiple_in_preamble.pl
index 03fe408f71..64a36ab02f 100644
--- a/tp/t/results/languages/multiple_in_preamble.pl
+++ b/tp/t/results/languages/multiple_in_preamble.pl
@@ -73,7 +73,8 @@ $result_trees{'multiple_in_preamble'} = {
                               'contents' => [
                                 {
                                   'extra' => {
-                                    'documentlanguage' => 'fr'
+                                    'documentlanguage' => 'fr',
+                                    'translation_context' => 'category of 
instance variables in object-oriented programming for @defivar'
                                   },
                                   'text' => 'Instance Variable',
                                   'type' => 'untranslated'
@@ -462,7 +463,8 @@ $result_trees{'multiple_in_preamble'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'hr'
+                            'documentlanguage' => 'hr',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -681,7 +683,8 @@ $result_trees{'multiple_in_preamble'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'de'
+                            'documentlanguage' => 'de',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/multiple_in_preamble_before_node.pl 
b/tp/t/results/languages/multiple_in_preamble_before_node.pl
index 1b9c9e8aa5..7244f77be4 100644
--- a/tp/t/results/languages/multiple_in_preamble_before_node.pl
+++ b/tp/t/results/languages/multiple_in_preamble_before_node.pl
@@ -73,7 +73,8 @@ $result_trees{'multiple_in_preamble_before_node'} = {
                               'contents' => [
                                 {
                                   'extra' => {
-                                    'documentlanguage' => 'fr'
+                                    'documentlanguage' => 'fr',
+                                    'translation_context' => 'category of 
instance variables in object-oriented programming for @defivar'
                                   },
                                   'text' => 'Instance Variable',
                                   'type' => 'untranslated'
@@ -513,7 +514,8 @@ $result_trees{'multiple_in_preamble_before_node'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'de'
+                            'documentlanguage' => 'de',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/multiple_lang_chapters.pl 
b/tp/t/results/languages/multiple_lang_chapters.pl
index 254a71b26f..faa2ba1b70 100644
--- a/tp/t/results/languages/multiple_lang_chapters.pl
+++ b/tp/t/results/languages/multiple_lang_chapters.pl
@@ -731,7 +731,8 @@ $result_trees{'multiple_lang_chapters'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'ja'
+                            'documentlanguage' => 'ja',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -1023,7 +1024,8 @@ $result_trees{'multiple_lang_chapters'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'en'
+                            'documentlanguage' => 'en',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -1279,7 +1281,8 @@ $result_trees{'multiple_lang_chapters'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr_FR'
+                            'documentlanguage' => 'fr_FR',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/multiple_lang_chapters_latex.pl 
b/tp/t/results/languages/multiple_lang_chapters_latex.pl
index a531e42a1a..f2d0e86622 100644
--- a/tp/t/results/languages/multiple_lang_chapters_latex.pl
+++ b/tp/t/results/languages/multiple_lang_chapters_latex.pl
@@ -731,7 +731,8 @@ $result_trees{'multiple_lang_chapters_latex'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'ja'
+                            'documentlanguage' => 'ja',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -1023,7 +1024,8 @@ $result_trees{'multiple_lang_chapters_latex'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'en'
+                            'documentlanguage' => 'en',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -1279,7 +1281,8 @@ $result_trees{'multiple_lang_chapters_latex'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr_FR'
+                            'documentlanguage' => 'fr_FR',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/multiple_lang_chapters_texi2html.pl 
b/tp/t/results/languages/multiple_lang_chapters_texi2html.pl
index 46b4983d4d..62c3e7e0c3 100644
--- a/tp/t/results/languages/multiple_lang_chapters_texi2html.pl
+++ b/tp/t/results/languages/multiple_lang_chapters_texi2html.pl
@@ -698,7 +698,8 @@ $result_trees{'multiple_lang_chapters_texi2html'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'ja'
+                            'documentlanguage' => 'ja',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -990,7 +991,8 @@ $result_trees{'multiple_lang_chapters_texi2html'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'en'
+                            'documentlanguage' => 'en',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
@@ -1246,7 +1248,8 @@ $result_trees{'multiple_lang_chapters_texi2html'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr_FR'
+                            'documentlanguage' => 'fr_FR',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/simple_documentlanguage.pl 
b/tp/t/results/languages/simple_documentlanguage.pl
index db49cb37b7..353866e00d 100644
--- a/tp/t/results/languages/simple_documentlanguage.pl
+++ b/tp/t/results/languages/simple_documentlanguage.pl
@@ -121,7 +121,8 @@ $result_trees{'simple_documentlanguage'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr'
+                            'documentlanguage' => 'fr',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'
diff --git a/tp/t/results/languages/unknown_region.pl 
b/tp/t/results/languages/unknown_region.pl
index 43919b882b..b33d9eb594 100644
--- a/tp/t/results/languages/unknown_region.pl
+++ b/tp/t/results/languages/unknown_region.pl
@@ -121,7 +121,8 @@ $result_trees{'unknown_region'} = {
                       'contents' => [
                         {
                           'extra' => {
-                            'documentlanguage' => 'fr_NOWHERE'
+                            'documentlanguage' => 'fr_NOWHERE',
+                            'translation_context' => 'category of instance 
variables in object-oriented programming for @defivar'
                           },
                           'text' => 'Instance Variable',
                           'type' => 'untranslated'



reply via email to

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