Skip to content

xenocrat/mo2array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

mo2array is a PHP class for decoding GNU gettext machine object (MO) files to array.

Requirements

  • PHP 8.0+

Usage

Decode MO file contents:

$mo = file_get_contents("example.mo");
$throw_exceptions = false;
$array = \xenocrat\mo2array::decode($mo, $throw_exceptions);
print_r($array);

The above example will output:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => 
                )
            [1] => Array
                (
                    [0] => Language: it_IT
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Plural-Forms: nplurals=2; plural=(n != 1);
Project-Id-Version: 
PO-Revision-Date: 
Last-Translator: 
Language-Team: 
X-Generator: Poedit 2.2.4
                )
        )
    [1] => Array
        (
            [0] => Array
                (
                    [0] => goodbye
                )
            [1] => Array
                (
                    [0] => arrivederci
                )
        )
    [2] => Array
        (
            [0] => Array
                (
                    [0] => hello
                )
            [1] => Array
                (
                    [0] => ciao
                )
        )
    [3] => Array
        (
            [0] => Array
                (
                    [0] => message
                    [1] => messages
                )
            [1] => Array
                (
                    [0] => messagio
                    [1] => messagi
                )
        )
)

Methods

decode

Description

public static mo2array::decode(
    string $mo,
    int $throw_exceptions = false
): array|false

Decodes a GNU gettext machine object file.

Parameters

  • mo

    A complete MO file as a string of data.

  • throw_exceptions

    Whether or not to throw exceptions for decoding errors.

Return Values

Returns an array of the original strings and translation strings discovered in the MO file, or false if the file contents cannot be decoded. Strings discovered in the MO file are returned as encoded.

About

A PHP class for decoding GNU gettext machine object (MO) files to array.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages