7class PhpArray
extends Generator implements GeneratorInterface
12 public static function toString(Translations $translations)
16 return '<?php return '.var_export($array,
true).
'; ?>';
26 public static function toArray(Translations $translations)
28 $array = static::buildArray($translations);
30 $domain = $translations->getDomain() ?:
'messages';
31 $lang = $translations->getLanguage() ?:
'en';
38 'plural-forms' =>
'nplurals=2; plural=(n != 1);',
43 if ($translations->getHeader(
'Plural-Forms') !==
null) {
44 $fullArray[
$domain][
''][
'plural-forms'] = $translations->getHeader(
'Plural-Forms');
59 protected static function buildArray(Translations $translations)
63 $context_glue =
"\004";
65 foreach ($translations as $translation) {
66 $key = ($translation->hasContext() ? $translation->getContext().$context_glue :
'').$translation->getOriginal();
67 $entry = array($translation->getPlural(), $translation->getTranslation());
69 if ($translation->hasPluralTranslation()) {
70 $entry = array_merge($entry, $translation->getPluralTranslation());
73 $array[
$key] = $entry;
if(!array_key_exists('domain', $_REQUEST)) $domain
An exception for terminatinating execution or to throw for unit testing.
Class to manage a collection of translations.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
toArray($value)
Wrap the given value in an array if it is no array.