Scroll to navigation

Zonemaster::Engine::Translator(3pm) User Contributed Perl Documentation Zonemaster::Engine::Translator(3pm)

NAME

Zonemaster::Engine::Translator - translation support for Zonemaster

SYNOPSIS

    Zonemaster::Engine::Translator->initialize( locale => 'sv_SE.UTF-8' );
    my $trans = Zonemaster::Engine::Translator->instance;
    say $trans->to_string($entry);

This is a singleton class.

The instance of this class requires exclusive control over $ENV{LC_MESSAGES} and the program's underlying LC_MESSAGES. At times it resets gettext's textdomain. On construction it unsets $ENV{LC_ALL} and from then on it must remain unset.

On systems that support $ENV{LANGUAGE}, this variable overrides the locale() attribute unless the locale() attribute is set to "C".

ATTRIBUTES

The locale used for localized messages.

    say $translator->locale();
    if ( !$translator->locale( 'sv_SE.UTF-8' ) ) {
        say "failed to update locale";
    }
    

The value of this attribute is mirrored in $ENV{LC_MESSAGES}.

When writing to this attribute, a request is made to update the program's underlying LC_MESSAGES. If this request fails, the attribute value remains unchanged and an empty list is returned.

As a side effect when successfully updating this attribute gettext's textdomain is reset.

A reference to a hash with translation data. This is unlikely to be useful to end-users.

METHODS

Provide initial values for the single instance of this class.

    Zonemaster::Engine::Translator->initialize( locale => 'sv_SE.UTF-8' );
    

This method must be called at most once and before the first call to instance().

Returns the single instance of this class.

    my $translator = Zonemaster::Engine::Translator->instance;
    

If initialize() has not been called prior to the first call to instance(), it is the same as if initialize() had been called without arguments.

Use of this method is deprecated.
If no initial value is provided to the constructor, one is determined by calling setlocale( LC_MESSAGES, "" ).
Takes a Zonemaster::Engine::Logger::Entry object as its argument and returns a translated string with the timestamp, level, message and arguments in the entry.
Takes a Zonemaster::Engine::Logger::Entry object as its argument and returns a translation of its tag and arguments.
Takes a string (test case ID) and returns the translated test case description.
Internal method that's only mentioned here to placate Pod::Coverage.
2024-08-08 perl v5.38.2