[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Translations.pm (translate_string, g
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Translations.pm (translate_string, gdt, gdt_string): remove unused translate_string first argument. Do not remove the first argument of the user-defined $translate_string_method optionally passed to gdt and gdt_string. Update callers. |
Date: |
Fri, 02 Feb 2024 14:24:41 -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 a503fc95cb * tp/Texinfo/Translations.pm (translate_string, gdt,
gdt_string): remove unused translate_string first argument. Do not remove the
first argument of the user-defined $translate_string_method optionally passed
to gdt and gdt_string. Update callers.
a503fc95cb is described below
commit a503fc95cb4f8af6ec997ccb8904b067bb9aef01
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Feb 2 20:24:31 2024 +0100
* tp/Texinfo/Translations.pm (translate_string, gdt, gdt_string):
remove unused translate_string first argument. Do not remove the
first argument of the user-defined $translate_string_method optionally
passed to gdt and gdt_string. Update callers.
* tp/Texinfo/Translations.pm (_replace_substrings)
(_replace_convert_substrings): rename to make clear that the functions
are internal. Replace _replace_convert_substrings
$customization_information by $debug_level as it is the only variable
that is used and we want to keep it like this.
* tp/Texinfo/XS/main/translations.c (translate_string): remove unused
first argument. Update callers.
---
ChangeLog | 16 +++++
tp/Texinfo/Convert/HTML.pm | 4 +-
tp/Texinfo/Translations.pm | 114 +++++++++++++----------------------
tp/Texinfo/XS/convert/convert_html.c | 6 +-
tp/Texinfo/XS/main/translations.c | 6 +-
tp/Texinfo/XS/main/translations.h | 3 +-
6 files changed, 66 insertions(+), 83 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 35a16c4cdc..fc21c044e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-02-02 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Translations.pm (translate_string, gdt, gdt_string):
+ remove unused translate_string first argument. Do not remove the
+ first argument of the user-defined $translate_string_method optionally
+ passed to gdt and gdt_string. Update callers.
+
+ * tp/Texinfo/Translations.pm (_replace_substrings)
+ (_replace_convert_substrings): rename to make clear that the functions
+ are internal. Replace _replace_convert_substrings
+ $customization_information by $debug_level as it is the only variable
+ that is used and we want to keep it like this.
+
+ * tp/Texinfo/XS/main/translations.c (translate_string): remove unused
+ first argument. Update callers.
+
2024-02-02 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/Converter.pm (pcdt): call cdt.
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 1210a90d08..1af46e4cce 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -2842,7 +2842,7 @@ sub _translate_names($)
# redefined functions
#
# Texinfo::Translations::translate_string redefined to call user defined
function.
-sub html_translate_string($$;$$)
+sub html_translate_string($$$;$)
{
my ($self, $string, $lang, $translation_context) = @_;
if (defined($self->{'formatting_function'}->{'format_translate_message'})) {
@@ -2857,7 +2857,7 @@ sub html_translate_string($$;$$)
}
}
- return Texinfo::Translations::translate_string($self, $string, $lang,
+ return Texinfo::Translations::translate_string($string, $lang,
$translation_context);
}
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index e9af5a2f16..02d82f084c 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -136,8 +136,7 @@ sub _switch_messages_locale
$working_locale = $locale;
}
-# Get document translation - handle translations of in-document strings.
-# Return a parsed Texinfo tree
+# Return a translated string.
# $LANG set the language if set. If undef, the $DEFAULT_LANGUAGE variable
# is used.
# NOTE If called from a converter, $LANG will in general be set from the
@@ -146,14 +145,11 @@ sub _switch_messages_locale
# @documentlanguage before it is encountered. Some set some default
# based on @documentlanguage if in the preamble, some set some default
# language (in general en) in any case.
-# TODO redefined in HTML. Document?
-sub translate_string($$;$$)
+# Can be replaced by a call to a user-supplied function in gdt* with a
+# different prototype.
+sub translate_string($$;$)
{
- my ($customization_information, $string, $lang, $translation_context) = @_;
-
- if (defined($lang) and $lang eq '') {
- cluck ("BUG: defined but empty documentlanguage:
$customization_information: '$string'\n");
- }
+ my ($string, $lang, $translation_context) = @_;
$lang = $DEFAULT_LANGUAGE if (!defined($lang));
@@ -227,22 +223,32 @@ sub translate_string($$;$$)
}
# Get document translation - handle translations of in-document strings.
-# Return a parsed Texinfo tree
+# Return a parsed Texinfo tree.
+# $TRANSLATED_STRING_METHOD is optional. If set, it is called instead
+# of translate_string. $TRANSLATED_STRING_METHOD takes
+# $CUSTOMIZATION_INFORMATION as first argument in addition to other
+# translate_string arguments.
sub gdt($$;$$$$)
{
my ($customization_information, $string, $lang, $replaced_substrings,
$translation_context, $translate_string_method) = @_;
- if (!$translate_string_method) {
- $translate_string_method = \&translate_string;
+ my $translated_string;
+ if ($translate_string_method) {
+ $translated_string = &$translate_string_method($customization_information,
+ $string, $lang, $translation_context);
+ } else {
+ $translated_string = translate_string($string, $lang,
$translation_context);
}
- my $translated_string = &$translate_string_method($customization_information,
- $string, $lang, $translation_context);
+ my $debug_level;
+ if ($customization_information) {
+ $debug_level = $customization_information->get_conf('DEBUG');
+ }
- my $result_tree = replace_convert_substrings($customization_information,
- $translated_string,
- $replaced_substrings);
+ my $result_tree
+ = _replace_convert_substrings($translated_string, $replaced_substrings,
+ $debug_level);
#print STDERR "GDT '$string' '$translated_string' '".
# Texinfo::Convert::Texinfo::convert_to_texinfo($result_tree)."'\n";
return $result_tree;
@@ -256,20 +262,19 @@ sub gdt_string($$;$$$$)
my ($customization_information, $string, $lang, $replaced_substrings,
$translation_context, $translate_string_method) = @_;
- if (!$translate_string_method) {
- $translate_string_method = \&translate_string;
- }
-
- my $translated_string = &$translate_string_method($customization_information,
+ my $translated_string;
+ if ($translate_string_method) {
+ $translated_string = &$translate_string_method($customization_information,
$string, $lang, $translation_context);
+ } else {
+ $translated_string = translate_string($string, $lang,
$translation_context);
+ }
- return replace_substrings ($customization_information, $translated_string,
- $replaced_substrings);
+ return _replace_substrings ($translated_string, $replaced_substrings);
}
-sub replace_substrings($$;$)
+sub _replace_substrings($;$)
{
- my $customization_information = shift;
my $translated_string = shift;
my $replaced_substrings = shift;
@@ -283,12 +288,11 @@ sub replace_substrings($$;$)
return $translation_result;
}
-
-sub replace_convert_substrings($$;$)
+sub _replace_convert_substrings($;$$)
{
- my $customization_information = shift;
my $translated_string = shift;
my $replaced_substrings = shift;
+ my $debug_level = shift;
my $texinfo_line = $translated_string;
@@ -308,20 +312,17 @@ sub replace_convert_substrings($$;$)
# location in tree of substituted brace enclosed strings.
my $parser_conf = {'accept_internalvalue' => 1};
- # general customization relevant for parser
- if ($customization_information) {
- my $debug_level = $customization_information->get_conf('DEBUG');
- # one less debug level for the gdt parser.
- if (defined($debug_level)) {
- if ($debug_level > 0) {
- $debug_level--;
- }
- $parser_conf->{'DEBUG'} = $debug_level;
+ # set parser debug level to one less than $debug_level
+ if (defined($debug_level)) {
+ my $parser_debug_level = $debug_level;
+ if ($parser_debug_level > 0) {
+ $parser_debug_level--;
}
+ $parser_conf->{'DEBUG'} = $parser_debug_level;
}
my $parser = Texinfo::Parser::simple_parser($parser_conf);
- if ($customization_information->get_conf('DEBUG')) {
+ if ($debug_level) {
print STDERR "IN TR PARSER '$texinfo_line'\n";
}
@@ -337,7 +338,7 @@ sub replace_convert_substrings($$;$)
}
}
$tree = _substitute($tree, $replaced_substrings);
- if ($customization_information->get_conf('DEBUG')) {
+ if ($debug_level) {
print STDERR "RESULT GDT: '".
Texinfo::Convert::Texinfo::convert_to_texinfo($tree)."'\n";
}
@@ -603,39 +604,6 @@ in the Gettext C API.
=back
-=begin comment
-
-The C<replace_convert_substrings> method is called by C<gdt> to substitute
-replaced substrings in a translated string and convert to a Texinfo tree.
-The C<replace_substrings> method is called by C<gdt_string> to substitute
-replaced substrings in a translated string.
-
-=over
-
-=item $tree = $object->replace_convert_substrings($translated_string,
$replaced_substrings)
-
-=item $string = $object->replace_substrings($translated_string,
$replaced_substrings)
-
-X<C<replace_convert_substrings>> X<C<replace_substrings>>
-
-I<$translated_string> is a string already translated. I<$replaced_substrings>
-is an optional hash reference specifying some substitution to be done.
-I<$object> is typically a converter, but can be any object that implements
-C<get_conf>, or undefined (C<undef>). If not undefined, the information in the
-I<$object> is used to get some customization information.
-
-C<replace_convert_substrings> performs the substitutions of substrings in the
-translated string and converts to a Texinfo tree. It is called from C<gdt>
-after the retrieval of the translated string.
-
-C<replace_substrings> performs the substitutions of substrings in the
-translated string. It is called from C<gdt_string> after the retrieval of the
-translated string.
-
-=back
-
-=end comment
-
=head1 SEE ALSO
L<GNU gettext utilities manual|https://www.gnu.org/software/gettext/manual/>.
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 02b0749881..a976339dfe 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -587,7 +587,7 @@ html_translate_string (CONVERTER *self, const char *string,
return translated_string;
}
- return translate_string (self->conf, string, lang, translation_context);
+ return translate_string (string, lang, translation_context);
}
/* returns a document descriptor. */
@@ -600,7 +600,7 @@ html_cdt (const char *string, CONVERTER *self, const char
*lang,
int document_descriptor;
translated_string = html_translate_string (self, string, lang,
- translation_context);
+ translation_context);
document_descriptor
= replace_convert_substrings (self->conf, translated_string,
replaced_substrings);
@@ -661,7 +661,7 @@ html_cdt_string (const char *string, CONVERTER *self,
lang = self->conf->documentlanguage.string;
translated_string = html_translate_string (self, string, lang,
- translation_context);
+ translation_context);
result = replace_substrings (translated_string, replaced_substrings);
free (translated_string);
diff --git a/tp/Texinfo/XS/main/translations.c
b/tp/Texinfo/XS/main/translations.c
index 8f2a310807..c5bb1771fa 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -149,7 +149,7 @@ switch_messages_locale (void)
}
char *
-translate_string (OPTIONS *options, const char * string, const char *in_lang,
+translate_string (const char * string, const char *in_lang,
const char *translation_context)
{
const char *lang = in_lang;
@@ -526,7 +526,7 @@ gdt (const char *string, OPTIONS *options, const char *lang,
NAMED_STRING_ELEMENT_LIST *replaced_substrings,
const char *translation_context)
{
- char *translated_string = translate_string (options, string, lang,
+ char *translated_string = translate_string (string, lang,
translation_context);
int document_descriptor
@@ -578,7 +578,7 @@ gdt_string (const char *string, OPTIONS *options, const
char *lang,
NAMED_STRING_ELEMENT_LIST *replaced_substrings,
const char *translation_context)
{
- char *translated_string = translate_string (options, string, lang,
+ char *translated_string = translate_string (string, lang,
translation_context);
char *result = replace_substrings (translated_string, replaced_substrings);
diff --git a/tp/Texinfo/XS/main/translations.h
b/tp/Texinfo/XS/main/translations.h
index 1219def509..1406fcae41 100644
--- a/tp/Texinfo/XS/main/translations.h
+++ b/tp/Texinfo/XS/main/translations.h
@@ -24,8 +24,7 @@ typedef struct NAMED_STRING_ELEMENT_LIST {
void configure_output_strings_translations (char *localesdir,
char *strings_textdomain_in);
-char *translate_string (OPTIONS *options, const char * string,
- const char *lang,
+char *translate_string (const char * string, const char *lang,
const char *translation_context);
int replace_convert_substrings (OPTIONS *options, char *translated_string,
NAMED_STRING_ELEMENT_LIST *replaced_substrings);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Translations.pm (translate_string, gdt, gdt_string): remove unused translate_string first argument. Do not remove the first argument of the user-defined $translate_string_method optionally passed to gdt and gdt_string. Update callers.,
Patrice Dumas <=