ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpArray.php
Go to the documentation of this file.
1<?php
2
3namespace Gettext\Generators;
4
6
7class 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}
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
An exception for terminatinating execution or to throw for unit testing.
Class to manage a collection of translations.
$key
Definition: croninfo.php:18
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
toArray($value)
Wrap the given value in an array if it is no array.