API / Minn\I18n / MoFile

MoFile final class

Minn\I18n\MoFile · public/minn/src/Minn/I18n/MoFile.php · 148 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}>
staticwritePairs(string $headerBlock, array $pairs): string#

A .mo file's bytes for a header block and its originals and translations as written (MO::export with its export_* steps), sorted.

$pairsarray<array-key, string>each original to its translations
staticwriteAsHeld(array $headers, array $entries): string#

A .mo file's bytes for headers and entries kept in the order they are held, the header block first (WP_Translation_File_MO::export, probe blocks-rest-widget-doubts).

$headersarray<string, string>
$entriesarray<string, array{translations: list<string>, plural: ?string}>
staticrevision(string $bytes): ?int#

The file's format revision: only 0 is read (probe translation-files).

Internals 5

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

privatepacked(array $pairs): string#
$pairsarray<array-key, string>each original to its translations, in the file's order
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>