To customize strings translations, register the format_translate_string
function reference:
$translated_tree
format_translate_string ($converter, $string, $lang, \%variables_hash, $translation_context, $mode)
¶$string is the string to be translated, $lang is the language. $translation_context is an optional translation context. $mode is an optional string which should modify how the function behaves.
The result returned should be a perl Texinfo tree in the default case, or
a string if $mode is set to translated_text
.
The result returned may also be ‘undef’, in which case the translation
is done as if the function reference had not been defined.
See Internationalization of Strings Function for more information on strings translations function arguments.
The replace_convert_substrings
method of Texinfo::Translations
can be used to substitute \%variables_hash and return a Texinfo tree
based on a translated string, taking into account $mode
(see Texinfo::Translations replace_convert_substrings).
This function reference is not set in the default case, in the default case
the gdt
method from the Texinfo::Translations
module is
called (see Internationalization of Strings Function).
See Specific formating Functions for information on how to register and get
the function reference.
Here is an example with new translated strings added and definition
of format_translate_string
to translate the strings:
texinfo_register_no_arg_command_formatting('error', undef, undef, undef, 'error-->'); my %translations = ( 'fr' => { 'error-->' => {'' => 'erreur-->',}, # ... }, 'de' => { 'error-->' => {'' => 'Fehler-->',}, # ... } # ... ); sub my_format_translate_string($$$;$$$) { my ($self, $string, $lang, $replaced_substrings, $translation_context, $type) = @_; $translation_context = '' if (!defined($translation_context)); if (exists($translations{$lang}) and exists($translations{$lang}->{$string}) and exists($translations{$lang}->{$string} ->{$translation_context})) { my $translation = $translations{$lang}->{$string} ->{$translation_context}; return $self->replace_convert_substrings($translation, $replaced_substrings, $type); } return undef; } texinfo_register_formatting_function('format_translate_string', \&my_format_translate_string);