23 if ($translations ===
null) {
30 if (($magic === self::MAGIC1) || ($magic === self::MAGIC3)) {
32 } elseif ($magic === (self::MAGIC2 & 0xFFFFFFFF)) {
35 throw new Exception(
'Not MO file');
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])) {
76 $context = $chunks[0];
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));
An exception for terminatinating execution or to throw for unit testing.
Class to manage a collection of translations.
$stream
PHP stream implementation.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file