23 if ($translations === null) {
28 $magic = self::readInt(
$stream,
'V');
30 if (($magic === self::MAGIC1) || ($magic === self::MAGIC3)) {
32 } elseif ($magic === (self::MAGIC2 & 0xFFFFFFFF)) {
38 self::readInt(
$stream, $byteOrder);
41 $originals = self::readInt(
$stream, $byteOrder);
42 $tran = self::readInt(
$stream, $byteOrder);
45 $table_originals = self::readIntArray(
$stream, $byteOrder,
$total * 2);
48 $table_translations = self::readIntArray(
$stream, $byteOrder,
$total * 2);
53 $stream->seekto($table_originals[$next + 2]);
54 $original =
$stream->read($table_originals[$next + 1]);
56 $stream->seekto($table_translations[$next + 2]);
57 $translated =
$stream->read($table_translations[$next + 1]);
59 if ($original ===
'') {
61 foreach (explode(
"\n", $translated) as $headerLine) {
62 if ($headerLine ===
'') {
66 $headerChunks = preg_split(
'/:\s*/', $headerLine, 2);
67 $translations->setHeader($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] :
'');
73 $chunks = explode(
"\x04", $original, 2);
75 if (isset($chunks[1])) {
77 $original = $chunks[1];
82 $chunks = explode(
"\x00", $original, 2);
84 if (isset($chunks[1])) {
85 $original = $chunks[0];
91 $translation = $translations->insert(
$context, $original, $plural);
93 if ($translated ===
'') {
98 $translation->setTranslation($translated);
102 foreach (explode(
"\x00", $translated) as $pluralIndex => $pluralValue) {
103 if ($pluralIndex === 0) {
104 $translation->setTranslation($pluralValue);
106 $translation->setPluralTranslation($pluralValue, $pluralIndex - 1);
111 return $translations;
120 if (($read = $stream->
read(4)) ===
false) {
124 $read = unpack($byteOrder, $read);
126 return array_shift($read);
136 return unpack($byteOrder.$count, $stream->
read(4 * $count));
$stream
PHP stream implementation.
read($bytes)
Read and returns a part of the string.
Class to manage a collection of translations.