15.2 Translated Strings Customization

To customize strings translations, register the format_translate_message function reference:

Function Reference: $translated_string format_translate_message ($converter, $string, $lang, $translation_context)

$string is the string to be translated, $lang is the language. $translation_context is an optional translation context.

The result returned should be the translated string. 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.

This function reference is not set in the default case, in the default case translate_string from the Texinfo::Translations module is called (see Internationalization of Strings Function). See Registering 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_message 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_message($$$;$)
{
  my ($self, $string, $lang, $translation_context) = @_;
  $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 $translation;
  }
  return undef;
}

texinfo_register_formatting_function('format_translate_message',
                                  \&my_format_translate_message);