API / Minn\I18n / MoFile

MoFile final class

Minn\I18n\MoFile · public/minn/src/Minn/I18n/MoFile.php · 106 lines

The GNU gettext binary catalog (.mo), read and written. The file opens with a magic number that also says its byte order, then a revision, the message count, and the offsets of two tables of (length, offset) pairs: the originals, then the translations. The entry with an empty original carries the headers; a plural original is "singular NUL plural" and its translations are NUL-separated; a context precedes the original with a 0x04 byte.

Uses 1

Constants and properties

privateMAGIC = 2500072158

Public

staticread(string $bytes): ?Minn\I18n\Catalog#

The catalog in a .mo file's bytes, or null when they are not one.

staticwrite(array $headers, array $entries): string#

A .mo file's bytes for headers and entries, little-endian, entries in the sorted order gettext expects.

$headersarray<string, string>
$entriesarray<string, array{translations: list<string>, plural: ?string}>

Internals 4

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatebyteOrder(string $bytes): ?string#

"V" for a little-endian file, "N" for a big-endian one, null for anything else.

privatestring(string $bytes, string $format, int $at): ?string#
privateheaders(string $block): array#
@return array<string, string>
privateheaderBlock(array $headers): string#
$headersarray<string, string>