Locale:...on::Hash(3)

πŸ“¦
version 1.036 Β· 2 versions
, in fedora 43

πŸ’– Locale::TextDomain::OO::Lexicon::Hash β€” the perl manual page, but make it cute ✨

okay so bestie, this is the manual page for Locale::TextDomain::OO::Lexicon::Hash from the User Contributed Perl Documentation, and it's genuinely one of the good ones. sit down, grab a strawberry πŸ“, and let's get into it.

it's called Lexicon from data structure, which is honestly the whole vibe in four words. obsessed.

$Id: Hash.pm 698 2017-09-28 05:21:05Z steffenw $
$HeadURL:
svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Lexicon/Hash.pm
$

✨ VERSION ✨

1.031 β€” that's the version, no cap πŸ’…


🌸 DESCRIPTION 🌸

This module allows to create a lexicon from data structure.

like. that's it. that's the whole serve. you hand it a Perl data structure, it hands you back a lexicon. iconic behavior honestly πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole thing in action, verbatim, because I would simply never lie to you:

require Locale::TextDomain::OO::Lexicon::Hash;
use Log::Any qw($log);

$logger = Locale::TextDomain::OO::Lexicon::Hash
    ->new(
        # all parameters are optional
        logger => sub {
            my ($message, $arg_ref) = @_;
            my $type = $arg_ref->{type}; # debug
            $log->$type($message);
            return;
        },
    )
    ->lexicon_ref({ ... })
    ->logger;

notice how it chains? new β†’ lexicon_ref β†’ logger. it's giving fluent interface, it's giving main character energy πŸ‘‘


πŸ’œ SUBROUTINES/METHODS πŸ’œ

🌈 method new

see SYNOPSIS

(yes bestie, that's literally all it says. the synopsis ate and left no crumbs, go look at it πŸ”₯)

🌈 method lexicon_ref

Fill in lexicon data from Perl data structure.

okay so here's the part where it gets specific, and you KNOW I'm keeping every detail:

For language "de-de", no category (default) and no domain (default) the lexicon name is "de-de::".

For language "en", category "LC_MESSAGES" and domain "test" the lexicon name is "en:LC_MESSAGES:test".

The keys of each item are stolen from PO file. Except the keys "msgstr_plural[0]", "msgstr_plural[1]", ... "msgstr_plural[N]" are written as key "msgstr_plural" with an array reference as value.

(stolen, not borrowed. PO files stay unbothered, we just take the keys πŸ’€)

$self->lexicon_ref({
    'de:MyCategory:MyDomain' . ':OptionalProject' => [
        # header in a very minimalistic form
        {
            msgid  => "",
            msgstr => ""
                . "Content-Type: text/plain; charset=UTF-8\n"
                . "Plural-Forms: nplurals=2; plural=n != 1;",
        },
        # single translation
        {
            msgid  => "help",
            msgstr => "Hilfe",
        },
        # with context
        {
            msgctxt => "datetime",
            msgid   => "date",
            msgstr  => "Datum",
        },
        # plural
        {
            msgid         => "person",
            msgid_plural  => "persons",
            msgstr_plural => [
                "Person",
                "Personen",
            ],
        },
        # plural with context
        {
            msgctxt       => "appointment",
            msgid         => "date",
            msgid_plural  => "dates",
            msgstr_plural => [
                "Date",
                "Dates",
            ],
        },
    ],
});

look at all those cases getting their moment: header, single translation, with context, plural, plural with context. every one of them got a slot. representation, we love to see it 🫢

🌈 method logger

Set the logger and get back them

(yeah, "them". the logger. we respect the logger's pronouns ✨)

$lexicon_hash->logger(
    sub {
        my ($message, $arg_ref) = @_;
        my $type = $arg_ref->{type};
        $log->$type($message);
        return;
    },
);
$logger = $lexicon_hash->logger;

$arg_ref contains

object => $lexicon_hash, # the object itself
type   => 'debug',
event  => 'lexicon,load', # The logger will be copied to
                          # Locale::TextDomain::OO::Singleton::Lexicon
                          # so more events are possible.

so it passes itself, the type, and the event. and the event is 'lexicon,load' β€” note the comma, not a colon, that's literally what it says, don't @ me πŸ™ˆ


⭐ EXAMPLE ⭐

Inside of this distribution is a directory named example. Run this *.pl files.

(yes, "this *.pl files". I am a faithful narrator and also a little bit of a menace. go run them, they slay πŸ”₯)


πŸ’… DIAGNOSTICS πŸ’…

confess

that's it. one word. it just tells on you. very demure, very mindful, very Carp-core πŸŽ€


🌸 CONFIGURATION AND ENVIRONMENT 🌸

none

nothing to configure, nothing to set, zero environment variables, she simply exists πŸ’–


🧚 DEPENDENCIES 🧚

  • Carp
  • Locale::TextDomain::OO::Singleton::Lexicon
  • Locale::TextDomain::OO::Util::ExtractHeader
  • Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
  • Moo
  • MooX::StrictConstructor
  • namespace::autoclean
  • Locale::TextDomain::OO::Role::Logger

the whole squad. Moo for the OO, MooX::StrictConstructor for the "no surprise attributes bestie" energy, namespace::autoclean for the tidy-up. a friend group 🫢


🌈 INCOMPATIBILITIES 🌈

not known

as far as anyone knows, she plays nice with everyone. no beef, no drama ✨


πŸ’€ BUGS AND LIMITATIONS πŸ’€

none

zero bugs, allegedly. we love a confident queen πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

Locale::TextDoamin::OO

okay so I need you to know β€” that's <red>TextDoamin</red>, not TextDomain. that's the typo in the original. I am preserving it exactly, character for character, because my job is to keep every detail, not to fix people's spelling. if the module is misspelled in the source, it's misspelled in my version. periodt πŸ’…

πŸ’– AUTHOR πŸ’–

Steffen Winkler

shoutout to Steffen, the author, the legend, the one who wrote all this down for us 🌟


Copyright (c) 2013 - 2017, Steffen Winkler "<steffenw at cpan.org>". All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

so yeah, free software, same terms as Perl itself, do what you want within those terms. slay πŸ¦‹


and that's the whole page bestie!! this came to you from perl v5.42.0, dated 2025-07-25, and it's the Locale:...on::Hash(3) manpage (the truncated one, you know the one). mwah πŸ’‹

πŸ“¦ where this page comes from