mo2array is a PHP class for decoding GNU gettext machine object (MO) files to array.
- PHP 8.0+
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
)
)
)
public static mo2array::decode(
string $mo,
int $throw_exceptions = false
): array|falseDecodes a GNU gettext machine object file.
-
mo
A complete MO file as a string of data.
-
throw_exceptions
Whether or not to throw exceptions for decoding errors.
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.