Locale::MO::File(3)
π 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:
charnamesnamespace::autocleanCarpConst::FastEncodeEnglishIO::FileMooMooX::StrictConstructorMooX::Types::MooseLike::BaseParams::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 π₯
- <http://www.gnu.org/software/hello/manual/gettext/MO-Files.html> β go read it, iykyk π
π AUTHOR π
Steffen Winkler β we love him, we thank him π«Ά.
π LICENSE AND COPYRIGHT π
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 wasLocale::MO::File(3)fromperl v5.42.0, dated2025-07-25. go forth and write some MO files, you gorgeous nerd ππ
π¦ where this page comes from
- fedora 43: perl-Locale-MO-File 0.09-20.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms