Locale::MO::File(3)

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

πŸ’– Locale::MO::File β€” the manual page, but make it cute ✨

okay so bestie, welcome to Locale::MO::File(3), straight out of the User Contributed Perl Documentation section πŸŽ€. This is your one-stop shop for reading and writing gettext MO files, and honestly? it's giving main character energy πŸ¦‹.


🌸 NAME 🌸

Locale::MO::File β€” write/read gettext MO files. no cap, that's the whole vibe πŸ’…

$Id: File.pm 645 2018-12-24 10:16:32Z steffenw $

$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/dbd-po/code/Locale-MO-File/trunk/lib/Locale/MO/File.pm $


⭐ VERSION ⭐

0.09 β€” yeah she's an older queen but she still slays πŸ‘‘


✨ SYNOPSIS ✨

here's the whole mood, copy-paste ready, no edits from me because details are sacred πŸ’œ:

require Locale::MO::File;

my $mo = Locale::MO::File->new(
    filename => $filename,
    ...
    messages => [
        {
            msgid  => 'original',
            msgstr => 'translation',
            ...
        },
        ...
    ],
});
$mo->write_file;

$mo->read_file;
my $messages = $self->get_messages;

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically this module lets you write or read gettext MO files, which is a whole thing and we love her for it πŸ’–.

The data you're gonna write? It comes in as an array reference of hash references. And the data you read back? Also lands in an array reference. symmetric. iconic. we stan 🌈.

You can also do the reading and writing with a file handle you've already opened, if that's more your speed. Heads up though β€” a given file handle will be used but not closed. not me leaving the door open πŸ™ˆ.

And fr fr: set your encoding, newline and byte order so everything's compatible. vibe check your bytes before you commit, bestie ✨.


πŸŽ€ SUBROUTINES/METHODS πŸŽ€

πŸ’… method new

This is the constructor method, aka where the magic starts. All parameters are optional β€” yes, all of them, she's chill like that 🫢.

my $mo = Locale::MO::File->new(
    filename      => $string,
    file_handle   => $file_handle, # filename expected for error messages only
    encoding      => $string,      # e.g. 'UTF-8', if not set: bytes
    newline       => $string,      # e.g. $CRLF or "\n", if not set: no change
    is_big_endian => $boolean,     # if not set: little endian
    messages      => $arrayref,    # default []
);

okay note the little comments up there because they MATTER, don't skip them πŸ‘€.

🌸 methods to modify an existing object 🌸

set_filename, get_filename, clear_filename

Modification of attribute filename β€” get, set, or yeet it:

$mo->set_filename($string);
$string = $mo->get_filename;
$mo->clear_filename;

set_file_handle, get_file_handle, clear_file_handle

Modification of attribute file_handle. same deal, different attribute πŸ’œ.

set_encoding, get_encoding, clear_encoding

Modification of attribute encoding. keep your bytes cute ✨.

set_newline, get_newline, clear_newline

Modification of attribute newline. \n girlies rise up 😭.

set_is_big_endian, is_big_endian, clear_is_big_endian

Modification of attribute is_big_endian. And listen β€” this one is only needed to write files. reading figures it out on its own, she's smart like that πŸ’….

πŸ’– method set_messages, get_messages πŸ’–

Modification of attribute messages. here's every shape she takes, and I mean every one, no skips πŸŽ€:

$mo->set_messages([
    # header
    {
        msgid   => q{},
        msgstr  => $header,
    },
    # typical
    {
        msgid   => $original,
        msgstr  => $translation,
    },
    # context
    {
        msgctxt => $context,
        msgid   => $original,
        msgstr  => $translation,
    },
    # plural
    {
        msgid         => $original_singular,
        msgid_plural  => $original_plural,
        msgstr_plural => [ $tanslation_0, ..., $translation_n ],
    },
    # context + plural
    {
        msgctxt       => $context,
        msgid         => $original_singular,
        msgid_plural  => $original_plural,
        msgstr_plural => [ $tanslation_0, ..., $translation_n ],
    },
]);

(yes, $tanslation_0 β€” that's how it's spelled in the source, and I am not about to fix a legend 🫢)

πŸ”₯ method write_file πŸ”₯

The content of the messages array reference gets first sorted, then written. Which means the header is always on top β€” periodt πŸ‘‘. And the messages array reference you handed over? it remains unchanged. she does not mess with your data, she's a respectful queen 🌈.

$mo->write_file;

🌟 method read_file 🌟

Big endian or little endian? detected automaticly. and the read data lands in the attribute messages. obsessed 😍.

$mo = read_file;
my $messages = $mo->get_messages;

🧚 EXAMPLE 🧚

Inside of this distribution there's a directory named example. Go run the *.pl files in it. that's it, that's the assignment ✨.


πŸ’€ DIAGNOSTICS πŸ’€

Full validation of the messages array reference using Params::Validate. so if you mess up, she WILL tell you, gently but firmly 😭.


🌈 CONFIGURATION AND ENVIRONMENT 🌈

none β€” literally nothing. no env vars, no config files, no drama. she's low maintenance πŸ’œ.


πŸ“ DEPENDENCIES πŸ“

okay so she does lean on a few friends, and they're all listed here, all of them, no cap:

  • charnames
  • namespace::autoclean
  • Carp
  • Const::Fast
  • Encode
  • English
  • IO::File
  • Moo
  • MooX::StrictConstructor
  • MooX::Types::MooseLike::Base
  • Params::Validate

πŸ™ˆ INCOMPATIBILITIES πŸ™ˆ

not known β€” as far as anyone can tell, she plays nice with everyone 🫢.


πŸ‘‘ BUGS AND LIMITATIONS πŸ‘‘

Real talk: the hashing table is not written by this module version. Which means the result is very slim MO files β€” cute, tiny, maybe a little too skinny, but that's the deal 🌸.

lowkey important, highkey true: no hashing table, just slim files πŸ’…

πŸ”₯ SEE ALSO πŸ”₯


πŸ’– AUTHOR πŸ’–

Steffen Winkler β€” we love him, we thank him 🫢.


Copyright (c) 2011 - 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. slay, legally speaking πŸ’œ.


and that's the whole page bestie βœ¨πŸ’–πŸ¦‹πŸŒΈπŸ’…

cute lil sign-off: this was Locale::MO::File(3) from perl v5.42.0, dated 2025-07-25. go forth and write some MO files, you gorgeous nerd πŸŽ€πŸ‘‘
πŸ“¦ where this page comes from