Zonema...slator(3pm)

πŸ‘‘ Zonemaster::Engine::Translator β€” aka the translation bestie πŸ’–

okay so this is the page for Zonemaster::Engine::Translator(3pm) β€” it's part of the User Contributed Perl Documentation and it's basically the translator support for Zonemaster. she speaks every language, no cap 🌈


✨ SYNOPSIS ✨

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

my $trans = Zonemaster::Engine::Translator->instance;
say $trans->to_string($entry);

bestie, listen β€” this is a singleton class. one instance, one queen, no duplicates periodt πŸ‘‘

so the way this works: the instance of this class needs exclusive control over $ENV{LC_MESSAGES} and the program's underlying LC_MESSAGES. like, nobody else gets to touch them. also at times it resets gettext's textdomain. and on construction it unsets $ENV{LC_ALL}, and from then on it must remain unset. fr fr, don't go re-setting it, that's not the vibe 🚫

on systems that support $ENV{LANGUAGE}, this variable overrides the locale() attribute β€” unless the locale() attribute is set to "C". so "C" is the one thing that fights back, iconic πŸ’…


🌸 ATTRIBUTES 🌸

  • locale β€” the locale used for localized messages. the whole glow-up language situation πŸ’«
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}. cute, right? πŸ’–

when you write to this attribute, a request is made to update the program's underlying LC_MESSAGES. and if that request fails? the attribute value stays exactly as it was and an empty list is returned. no update, no drama, we move on 🫢

and as a side effect, when this attribute is successfully updated, gettext's textdomain gets reset. just so you know ✨

  • data β€” a reference to a hash with translation data. ngl this one is unlikely to be useful to end-users, it's giving internal 🌚
  • all_tag_descriptions β€” that's it. that's the whole entry. she's mysterious, she's lowkey serving main character energy with no description πŸ‘‘

πŸ”₯ METHODS πŸ”₯

  • initialize(%args) β€” gives you the initial values for the single instance of this class. you literally do this:
Zonemaster::Engine::Translator->initialize( locale => 'sv_SE.UTF-8' );

important: this method must be called at most once, and it has to happen before the first call to instance(). not twice, not after. read the rules bestie 😭

  • instance() β€” returns the single instance of this class. the one and only, the main character πŸ’…
my $translator = Zonemaster::Engine::Translator->instance;

and if initialize() was never called before that first instance() call? it's the same as if initialize() had been called without any arguments. she just shows up fully formed, no cap ✨

  • new(%args) β€” 🚨 use of this method is deprecated. yeah, deprecated deprecated. we don't do that here anymore 😭
    • locale β€” if no initial value is provided to the constructor, one is determined by calling setlocale( LC_MESSAGES, "" ). so it goes and figures it out itself, independent queen πŸŽ€
  • to_string($entry) β€” 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. all four, bundled up, one pretty string, we love a glow-up 🌸
  • translate_tag($entry) β€” takes a Zonemaster::Engine::Logger::Entry object as its argument and returns a translation of its tag and arguments. just the tag and args, no timestamp, no message πŸ’œ
  • test_case_description($testcase) β€” takes a string (a test case ID) and returns the translated test case description. hand her an ID, she hands you words πŸ”₯
  • BUILD β€” internal method that's only mentioned here to placate Pod::Coverage. yes, she's literally just here so the coverage checker stops side-eyeing us πŸ’€

⭐ quick recap so you don't fumble: call initialize() once, before instance(), keep $ENV{LC_ALL} unset forever, and remember that $ENV{LANGUAGE} runs the show unless locale() is "C". slay responsibly 🫢

and that's the whole page bestie!! this one was documented as perl v5.40.1, dated 2026-03-21, from the Zonema...slator(3pm) page β€” so go forth and translate the entire internet, you've got this πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from