Locale:...le::File(3)

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

πŸ’– Locale::TextDomain::OO::Lexicon::Role::File(3) πŸ’–

okay bestie so this is a page from the User Contributed Perl Documentation, and the module we're stanning today is Locale::TextDomain::OO::Lexicon::Role::File πŸŽ€ it's a helper role that adds a lexicon from a file, and honestly? iconic behaviour.

$Id: File.pm 722 2018-12-21 12:24:14Z steffenw $

$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Lexicon/Role/File.pm $


✨ VERSION ✨

1.034 β€” she's been around, she's thriving πŸ’…


🌸 DESCRIPTION 🌸

This module provides methods to inplmement lexicon from file easy. yes, that's what the original says, and no, we're not fixing the typo, we're preserving it, that's the whole assignment 🫢 basically it gives you the methods to make a lexicon-from-file setup super easy.


πŸ¦‹ SYNOPSIS πŸ¦‹

with qw(
    Locale::TextDomain::OO::Lexicon::Role::File
);

that's it, that's the vibe check. you just with it. 🧚


πŸ‘‘ SUBROUTINES/METHODS πŸ‘‘

πŸ“ attribute decode_code

Allows to implement your own way of decode messages. Add a code ref in constructor.

decode_code => sub {
    my ($charset, $text) = @_;
    defined $text
        or return $text;

    return decode( $charset, $text );
},

so like, you bring your own decoding logic and drop it in the constructor. main character energy, your rules πŸ’œ

πŸ“ method lexicon_ref

$self->lexicon_ref({
    # required
    search_dirs => [ qw( ./my_dir ./my_other_dir ) ],
    # optional
    gettext_to_maketext => $boolean,
    # optional
    decode => $boolean,
    # required
    data => [
        # e.g. de.mo, en.mo read from:
        # search_dir/de.mo
        # search_dir/en.mo
        '*::' => '*.mo',

        # e.g. de.mo en.mo read from:
        # search_dir/subdir/de/LC_MESSAGES/domain.mo
        # search_dir/subdir/en/LC_MESSAGES/domain.mo
        '*:LC_MESSAGES:domain' => 'subdir/*/LC_MESSAGES/domain.mo',

        # Merge a region lexicon:
        # Take the header and messages of the "de::" lexicon,
        # overwrite the header and messages of the "de-at::" lexicon
        # and store that as "de-at::" lexicon with all messages now.
        merge_lexicon => 'de::', 'de-at::' => 'de-at::',

        # Copy a lexicon into another domain and/or category:
        copy_lexicon => 'i-default::' => 'i-default:LC_MESSAGES:domain',

        # Move a lexicon into another domain and/or category:
        move_lexicon => 'i-default::' => 'i-default:LC_MESSAGES:domain',

        # Delete a lexicon:
        delete_lexicon => 'i-default::',
    ],
});

so the tea here β˜•οΈ:

  • search_dirs is required β€” that's your array of dirs to look in.
  • gettext_to_maketext is optional β€” takes $boolean.
  • decode is optional β€” also takes $boolean.
  • data is required β€” this is the list where the actual magic happens:
    • '*::' => '*.mo' grabs stuff like de.mo, en.mo from search_dir/de.mo and search_dir/en.mo.
    • '*:LC_MESSAGES:domain' => 'subdir/*/LC_MESSAGES/domain.mo' grabs e.g. de.mo and en.mo from search_dir/subdir/de/LC_MESSAGES/domain.mo and search_dir/subdir/en/LC_MESSAGES/domain.mo.
    • merge_lexicon => 'de::', 'de-at::' => 'de-at::' merges a region lexicon β€” takes the header and messages of the de:: lexicon, overwrites the header and messages of the de-at:: lexicon, and stores that as the de-at:: lexicon with all messages now. slay.
    • copy_lexicon => 'i-default::' => 'i-default:LC_MESSAGES:domain' copies a lexicon into another domain and/or category.
    • move_lexicon => 'i-default::' => 'i-default:LC_MESSAGES:domain' moves a lexicon into another domain and/or category.
    • delete_lexicon => 'i-default::' deletes a lexicon. gone. πŸ’€

πŸ“ method logger

Set the logger and get back them. fr fr, that's the deal β€” set it, and it hands it right back to you.

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

and $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 object is the object itself, type is like 'debug', and event here is 'lexicon,load' β€” and lowkey important detail: the logger will be copied to Locale::TextDomain::OO::Singleton::Lexicon, so more events are possible. iykyk πŸ‘‘


🌈 EXAMPLE 🌈

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


πŸ”₯ DIAGNOSTICS πŸ”₯

confess


πŸ’œ CONFIGURATION AND ENVIRONMENT πŸ’œ

none. no config, no env vars, nothing to stress about, we love a low-maintenance queen.


πŸŽ€ DEPENDENCIES πŸŽ€

  • Carp
  • Encode
  • English
  • Locale::TextDomain::OO::Singleton::Lexicon
  • Locale::TextDomain::OO::Util::ExtractHeader
  • Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
  • Moo::Role
  • MooX::Types::MooseLike::Base
  • Path::Tiny
  • namespace::autoclean
  • Locale::TextDomain::OO::Lexicon::Role::GettextToMaketext
  • Locale::TextDomain::OO::Role::Logger

look at that roster, it's giving squad goals 🫢


πŸ™ˆ INCOMPATIBILITIES πŸ™ˆ

not known


😭 BUGS AND LIMITATIONS 😭

none. no bugs, no limitations, she's perfect, periodt.


⭐ SEE ALSO ⭐

Locale::TextDoamin::OO

(yes, spelled exactly like that β€” we do not touch the spelling, that's the rule πŸ’…)


πŸ’– AUTHOR πŸ’–

Steffen Winkler


Copyright (c) 2013 - 2018, 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.


and that's a wrap bestie 🌸 this page came to you via perl v5.42.0, dated 2025-07-25, under the manual name Locale:...le::File(3) β€” go forth and lexicon from file responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from