ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Gettext\Generators\Mo Class Reference
+ Inheritance diagram for Gettext\Generators\Mo:
+ Collaboration diagram for Gettext\Generators\Mo:

Static Public Member Functions

static toString (Translations $translations)
 {}. More...
 
- Static Public Member Functions inherited from Gettext\Generators\Generator
static toFile (Translations $translations, $file)
 Saves the translations in a file. More...
 
- Static Public Member Functions inherited from Gettext\Generators\GeneratorInterface
static toFile (Translations $translations, $file)
 Saves the translations in a file. More...
 

Static Public Attributes

static $includeEmptyTranslations = false
 

Detailed Description

Definition at line 7 of file Mo.php.

Member Function Documentation

◆ toString()

static Gettext\Generators\Mo::toString ( Translations  $translations)
static

{}.

Implements Gettext\Generators\GeneratorInterface.

Definition at line 14 of file Mo.php.

References $info, array, and Gettext\Translations\getHeaders().

15  {
16  $array = array();
17  $headers = '';
18 
19  foreach ($translations->getHeaders() as $headerName => $headerValue) {
20  $headers .= "$headerName: $headerValue\n";
21  }
22 
23  if ($headers !== '') {
24  $array[''] = $headers;
25  }
26 
27  foreach ($translations as $translation) {
28  if (!$translation->hasTranslation() && !static::$includeEmptyTranslations) {
29  continue;
30  }
31 
32  if ($translation->hasContext()) {
33  $originalString = $translation->getContext()."\x04".$translation->getOriginal();
34  } else {
35  $originalString = $translation->getOriginal();
36  }
37 
38  $array[$originalString] = $translation;
39  }
40 
41  ksort($array);
42  $numEntries = count($array);
43  $originalsTable = '';
44  $translationsTable = '';
45  $originalsIndex = array();
46  $translationsIndex = array();
47 
48  foreach ($array as $originalString => $translation) {
49  if (is_string($translation)) {
50  // Headers
51  $translationString = $translation;
52  } else {
53  /* @var $translation \Gettext\Translation */
54  if ($translation->hasPlural()) {
55  $originalString .= "\x00".$translation->getPlural();
56  }
57  $translationString = $translation->getTranslation();
58 
59  if ($translation->hasPluralTranslation()) {
60  $translationString .= "\x00".implode("\x00", $translation->getPluralTranslation());
61  }
62  }
63 
64  $originalsIndex[] = array('relativeOffset' => strlen($originalsTable), 'length' => strlen($originalString));
65  $originalsTable .= $originalString."\x00";
66  $translationsIndex[] = array('relativeOffset' => strlen($translationsTable), 'length' => strlen($translationString));
67  $translationsTable .= $translationString."\x00";
68  }
69 
70  // Offset of table with the original strings index: right after the header (which is 7 words)
71  $originalsIndexOffset = 7 * 4;
72 
73  // Size of table with the original strings index
74  $originalsIndexSize = $numEntries * (4 + 4);
75 
76  // Offset of table with the translation strings index: right after the original strings index table
77  $translationsIndexOffset = $originalsIndexOffset + $originalsIndexSize;
78 
79  // Size of table with the translation strings index
80  $translationsIndexSize = $numEntries * (4 + 4);
81 
82  // Hashing table starts after the header and after the index table
83  $originalsStringsOffset = $translationsIndexOffset + $translationsIndexSize;
84 
85  // Translations start after the keys
86  $translationsStringsOffset = $originalsStringsOffset + strlen($originalsTable);
87 
88  // Let's generate the .mo file binary data
89  $mo = '';
90 
91  // Magic number
92  $mo .= pack('L', 0x950412de);
93 
94  // File format revision
95  $mo .= pack('L', 0);
96 
97  // Number of strings
98  $mo .= pack('L', $numEntries);
99 
100  // Offset of table with original strings
101  $mo .= pack('L', $originalsIndexOffset);
102 
103  // Offset of table with translation strings
104  $mo .= pack('L', $translationsIndexOffset);
105 
106  // Size of hashing table: we don't use it.
107  $mo .= pack('L', 0);
108 
109  // Offset of hashing table: it would start right after the translations index table
110  $mo .= pack('L', $translationsIndexOffset + $translationsIndexSize);
111 
112  // Write the lengths & offsets of the original strings
113  foreach ($originalsIndex as $info) {
114  $mo .= pack('L', $info['length']);
115  $mo .= pack('L', $originalsStringsOffset + $info['relativeOffset']);
116  }
117 
118  // Write the lengths & offsets of the translated strings
119  foreach ($translationsIndex as $info) {
120  $mo .= pack('L', $info['length']);
121  $mo .= pack('L', $translationsStringsOffset + $info['relativeOffset']);
122  }
123 
124  // Write original strings
125  $mo .= $originalsTable;
126 
127  // Write translation strings
128  $mo .= $translationsTable;
129 
130  return $mo;
131  }
Create styles array
The data for the language used.
$info
Definition: index.php:5
+ Here is the call graph for this function:

Field Documentation

◆ $includeEmptyTranslations

Gettext\Generators\Mo::$includeEmptyTranslations = false
static

Definition at line 9 of file Mo.php.


The documentation for this class was generated from the following file: