Locale::MO::File - Write/read gettext MO files
$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 $
0.09
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;
The module allows to write or read gettext MO files.
Data to write are expected as array reference of hash references. Read data are stored in an array reference too.
Reading and writing is also available using an already open file handle. A given file handle will used but not closed.
Set encoding, newline and byte order to be compatible.
This is the constructor method. All parameters are optional.
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 [] );
Modification of attribute filename.
$mo->set_filename($string); $string = $mo->get_filename; $mo->clear_filename;
Modification of attribute file_handle.
Modification of attribute encoding.
Modification of attribute newline.
Modification of attribute is_big_endian. Only needed to write files.
Modification of attribute messages.
$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 ], }, ]);
The content of the "messages" array reference is first sorted and then written. So the header is always on top. The transferred "messages" array reference remains unchanged.
$mo->write_file;
Big endian or little endian will be detected automaticly. The read data will be stored in attribute messages.
$mo = read_file; my $messages = $mo->get_messages;
Inside of this distribution is a directory named example. Run the *.pl files.
Full validation of messages array reference using Params::Validate.
none
charnames
namespace::autoclean
Carp
Const::Fast
Encode
English
IO::File
Moo
MooX::StrictConstructor
MooX::Types::MooseLike::Base
Params::Validate
not known
Hashing table not written of this module version. So very slim MO files are the result.
http://www.gnu.org/software/hello/manual/gettext/MO-Files.html
Steffen Winkler
Copyright (c) 2011 - 2018, Steffen Winkler <steffenw at cpan.org>. All rights reserved.
<steffenw at cpan.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Locale::MO::File, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::MO::File
CPAN shell
perl -MCPAN -e shell install Locale::MO::File
For more information on module installation, please visit the detailed CPAN module installation guide.