NAME

Text::PO::MO - Machine Object File Read, Write

SYNOPSIS

    use Text::PO::MO;
        my $mo = Text::PO::MO->new( '/home/joe/locale/com.example.mo',
        {
            auto_decode => 1,
            encoding => 'utf-8',
            default_encoding => 'utf-8',
        });
        my $mo = Text::PO::MO->new(
            file => '/home/joe/locale/com.example.mo',
            auto_decode => 1,
            encoding => 'utf-8',
            default_encoding => 'utf-8',
        );
        my $hash = $mo->read;

VERSION

    v0.1.0

DESCRIPTION

This is the class for read from and writing to GNU .mo (machine object) files.

CONSTRUCTOR

new

Create a new Text::PO::MO object.

It accepts the following options:

auto_decode

Takes a boolean value and enables or disables auto decoding of data.

default_encoding

Sets the default encoding. This is used when auto_decode is enabled.

encoding

Sets the value of the encoding to use when auto_decode is enabled.

file

Sets or gets the .mo file to read.

use_cache

Takes a boolean value. If true, this will cache the data read by "read"

METHODS

as_object

Returns the data read from the machine object file as a Text::PO object.

auto_decode

Takes a boolean value and enables or disables auto decode of data read from .mo file.

This is used in "read"

decode

Provided with an hash reference of key-value pairs and a string representing an encoding and this will decode all its keys and values.

It returns the hash reference, although being a reference, this is not necessary.

default_encoding

Sets the default encoding to revert to if no encoding is set with "encoding" and "auto_decode" is enabled.

Otherwise, "read" will attempt to find out the encoding used by looking at the meta information Content-type

domain

Sets or gets the po file domain, such as com.example.api

encoding

Sets or gets the encoding to use for decoding the data read from the .mo file.

file

Sets or gets the gnu .mo file to be read from or written to.

read

Provided with a file path to a gnu .mo file and this returns an hash reference of key-value pairs corresponding to the msgid to msgstr or original text to localised text.

Note that there is one blank key corresponding to the meta informations.

It takes the following optional parameters:

auto_decode

Boolean value. If true, the data will be automatically decoded using either the character encoding specified with "encoding" or the one found in the Content-type field in the file meta information.

default_encoding

The default encoding to use if no encoding was set using "encoding" and none could be found in the .mo file meta information.

no_cache

Boolean value. If true, this will ignore any cached data and re-read the .mo file.

If caching is enabled with "use_cache", then "read" will return the cache instead of actually reading the .mo unless the last modification time has changed and increased.

reset

Resets the cached data. This will have the effect of reading the .mo file next time "read" is called.

Returns the current object.

revision

Sets or gets the revision number. This should not be changed, or you might break things.

It defaults to 0

use_cache

Takes a boolean value.

If true, this will enable caching based on the .mo file last modification timestamp.

Default to true.

write

Provided with a Text::PO object and this will write the .mo file.

It takes an hash reference of parameters:

file

The output file to write the data to.

This should be a file path, or - if you want to write to STDOUT.

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Text::PO, Text::PO::Element

https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html

http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html#MO-Files

COPYRIGHT & LICENSE

Copyright (c) 2020-2021 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.