Class to get gettext strings from .mo files.
More...
Class to get gettext strings from .mo files.
Definition at line 12 of file Mo.php.
◆ fromString()
static Gettext\Extractors\Mo::fromString |
( |
|
$string, |
|
|
Translations |
$translations = null , |
|
|
|
$file = '' |
|
) |
| |
|
static |
{Parses a string and append the translations found in the Translations instance.
- Parameters
-
string | $string | |
Translations | null | $translations | |
string | $file | The file path to insert the reference |
- Returns
- Translations
}
Implements Gettext\Extractors\ExtractorInterface.
Definition at line 21 of file Mo.php.
References $i, GuzzleHttp\Psr7\$stream, and $total.
23 if ($translations === null) {
24 $translations =
new Translations();
27 $stream =
new StringReader($string);
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])) {
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;
$stream
PHP stream implementation.
◆ readInt()
static Gettext\Extractors\Mo::readInt |
( |
StringReader |
$stream, |
|
|
|
$byteOrder |
|
) |
| |
|
staticprivate |
- Parameters
-
StringReader | $stream | |
string | $byteOrder | |
Definition at line 118 of file Mo.php.
References Gettext\Utils\StringReader\read().
120 if (($read =
$stream->read(4)) ===
false) {
124 $read = unpack($byteOrder, $read);
126 return array_shift($read);
$stream
PHP stream implementation.
◆ readIntArray()
static Gettext\Extractors\Mo::readIntArray |
( |
StringReader |
$stream, |
|
|
|
$byteOrder, |
|
|
|
$count |
|
) |
| |
|
staticprivate |
◆ MAGIC1
const Gettext\Extractors\Mo::MAGIC1 = -1794895138 |
◆ MAGIC2
const Gettext\Extractors\Mo::MAGIC2 = -569244523 |
◆ MAGIC3
const Gettext\Extractors\Mo::MAGIC3 = 2500072158 |
The documentation for this class was generated from the following file:
- libs/composer/vendor/gettext/gettext/src/Extractors/Mo.php