ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Gettext\Generators\Po Class Reference
+ Inheritance diagram for Gettext\Generators\Po:
+ Collaboration diagram for Gettext\Generators\Po:

Static Public Member Functions

static toString (Translations $translations)
 {}. More...
 
static convertString ($value)
 Convert a string to its PO representation. 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 Private Member Functions

static multilineQuote ($string)
 Escapes and adds double quotes to a string. More...
 
static addLines (array &$lines, $name, $value)
 Add one or more lines depending whether the string is multiline or not. More...
 

Detailed Description

Definition at line 7 of file Po.php.

Member Function Documentation

◆ addLines()

static Gettext\Generators\Po::addLines ( array &  $lines,
  $name,
  $value 
)
staticprivate

Add one or more lines depending whether the string is multiline or not.

Parameters
array&$lines
string$name
string$value

Definition at line 101 of file Po.php.

References $name.

102  {
103  $newLines = self::multilineQuote($value);
104 
105  if (count($newLines) === 1) {
106  $lines[] = $name.' '.$newLines[0];
107  } else {
108  $lines[] = $name.' ""';
109 
110  foreach ($newLines as $line) {
111  $lines[] = $line;
112  }
113  }
114  }

◆ convertString()

static Gettext\Generators\Po::convertString (   $value)
static

Convert a string to its PO representation.

Parameters
string$value
Returns
string

Definition at line 123 of file Po.php.

124  {
125  return '"'.strtr(
126  $value,
127  array(
128  "\x00" => '',
129  '\\' => '\\\\',
130  "\t" => '\t',
131  "\n" => '\n',
132  '"' => '\\"',
133  )
134  ).'"';
135  }

◆ multilineQuote()

static Gettext\Generators\Po::multilineQuote (   $string)
staticprivate

Escapes and adds double quotes to a string.

Parameters
string$string
Returns
string

Definition at line 78 of file Po.php.

79  {
80  $lines = explode("\n", $string);
81  $last = count($lines) - 1;
82 
83  foreach ($lines as $k => $line) {
84  if ($k === $last) {
85  $lines[$k] = self::convertString($line);
86  } else {
87  $lines[$k] = self::convertString($line."\n");
88  }
89  }
90 
91  return $lines;
92  }

◆ toString()

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

{}.

Implements Gettext\Generators\GeneratorInterface.

Definition at line 12 of file Po.php.

References $comment, $name, and Gettext\Translations\getHeaders().

13  {
14  $lines = array('msgid ""', 'msgstr ""');
15 
16  $headers = $translations->getHeaders();
17  $headers['PO-Revision-Date'] = date('c');
18 
19  foreach ($headers as $name => $value) {
20  $lines[] = '"'.$name.': '.$value.'\\n"';
21  }
22 
23  $lines[] = '';
24 
25  //Translations
26  foreach ($translations as $translation) {
27  if ($translation->hasComments()) {
28  foreach ($translation->getComments() as $comment) {
29  $lines[] = '# '.$comment;
30  }
31  }
32 
33  if ($translation->hasExtractedComments()) {
34  foreach ($translation->getExtractedComments() as $comment) {
35  $lines[] = '#. '.$comment;
36  }
37  }
38 
39  if ($translation->hasReferences()) {
40  foreach ($translation->getReferences() as $reference) {
41  $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null);
42  }
43  }
44 
45  if ($translation->hasFlags()) {
46  $lines[] = '#, '.implode(',', $translation->getFlags());
47  }
48 
49  if ($translation->hasContext()) {
50  $lines[] = 'msgctxt '.self::convertString($translation->getContext());
51  }
52 
53  self::addLines($lines, 'msgid', $translation->getOriginal());
54  if ($translation->hasPlural()) {
55  self::addLines($lines, 'msgid_plural', $translation->getPlural());
56  self::addLines($lines, 'msgstr[0]', $translation->getTranslation());
57 
58  foreach ($translation->getPluralTranslation() as $k => $v) {
59  self::addLines($lines, 'msgstr['.($k + 1).']', $v);
60  }
61  } else {
62  self::addLines($lines, 'msgstr', $translation->getTranslation());
63  }
64 
65  $lines[] = '';
66  }
67 
68  return implode("\n", $lines);
69  }
$comment
Definition: buildRTE.php:83
+ Here is the call graph for this function:

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