ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PhpArray.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Gettext\Generators;
4 
6 
7 class PhpArray extends Generator implements GeneratorInterface
8 {
12  public static function toString(Translations $translations)
13  {
14  $array = self::toArray($translations);
15 
16  return '<?php return '.var_export($array, true).'; ?>';
17  }
18 
26  public static function toArray(Translations $translations)
27  {
28  $array = static::buildArray($translations);
29 
30  $domain = $translations->getDomain() ?: 'messages';
31  $lang = $translations->getLanguage() ?: 'en';
32 
33  $fullArray = array(
34  $domain => array(
35  '' => array(
36  'domain' => $domain,
37  'lang' => $lang,
38  'plural-forms' => 'nplurals=2; plural=(n != 1);',
39  ),
40  ),
41  );
42 
43  if ($translations->getHeader('Plural-Forms') !== null) {
44  $fullArray[$domain]['']['plural-forms'] = $translations->getHeader('Plural-Forms');
45  }
46 
47  $fullArray[$domain] = array_merge($fullArray[$domain], $array);
48 
49  return $fullArray;
50  }
51 
59  protected static function buildArray(Translations $translations)
60  {
61  $array = array();
62 
63  $context_glue = "\004";
64 
65  foreach ($translations as $translation) {
66  $key = ($translation->hasContext() ? $translation->getContext().$context_glue : '').$translation->getOriginal();
67  $entry = array($translation->getPlural(), $translation->getTranslation());
68 
69  if ($translation->hasPluralTranslation()) {
70  $entry = array_merge($entry, $translation->getPluralTranslation());
71  }
72 
73  $array[$key] = $entry;
74  }
75 
76  return $array;
77  }
78 }
getDomain()
Returns the domain.
static toArray(Translations $translations)
Generates an array with the translations.
Definition: PhpArray.php:26
getHeader($name)
Returns a header value.
Class to manage a collection of translations.
getLanguage()
Returns the language value.
Create styles array
The data for the language used.
static toString(Translations $translations)
{Generates a string with the translations ready to save in a file.string}
Definition: PhpArray.php:12
toArray($value)
Wrap the given value in an array if it is no array.
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
static buildArray(Translations $translations)
Generates an array with all translations.
Definition: PhpArray.php:59
$key
Definition: croninfo.php:18