22 {
23 if ($translations === null) {
24 $translations = new Translations();
25 }
26
27 $stream =
new StringReader($string);
29
30 if (($magic === self::MAGIC1) || ($magic === self::MAGIC3)) {
31 $byteOrder = 'V';
32 } elseif ($magic === (self::MAGIC2 & 0xFFFFFFFF)) {
33 $byteOrder = 'N';
34 } else {
35 throw new Exception('Not MO file');
36 }
37
39
43
46
49
52
53 $stream->seekto($table_originals[$next + 2]);
54 $original =
$stream->read($table_originals[$next + 1]);
55
56 $stream->seekto($table_translations[$next + 2]);
57 $translated =
$stream->read($table_translations[$next + 1]);
58
59 if ($original === '') {
60
61 foreach (explode("\n", $translated) as $headerLine) {
62 if ($headerLine === '') {
63 continue;
64 }
65
66 $headerChunks = preg_split('/:\s*/', $headerLine, 2);
67 $translations->setHeader($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] : '');
68 }
69
70 continue;
71 }
72
73 $chunks = explode("\x04", $original, 2);
74
75 if (isset($chunks[1])) {
76 $context = $chunks[0];
77 $original = $chunks[1];
78 } else {
79 $context = '';
80 }
81
82 $chunks = explode("\x00", $original, 2);
83
84 if (isset($chunks[1])) {
85 $original = $chunks[0];
86 $plural = $chunks[1];
87 } else {
88 $plural = '';
89 }
90
91 $translation = $translations->insert($context, $original, $plural);
92
93 if ($translated === '') {
94 continue;
95 }
96
97 if ($plural === '') {
98 $translation->setTranslation($translated);
99 continue;
100 }
101
102 foreach (explode("\x00", $translated) as $pluralIndex => $pluralValue) {
103 if ($pluralIndex === 0) {
104 $translation->setTranslation($pluralValue);
105 } else {
106 $translation->setPluralTranslation($pluralValue, $pluralIndex - 1);
107 }
108 }
109 }
110
111 return $translations;
112 }
$stream
PHP stream implementation.