private static function store($locale, $entries) { $file = self::getFile($locale); $dir = dirname($file); if (!is_dir($dir)) { mkdir($dir, 0755, true); } Generators\Mo::toFile($entries, $file . 'mo'); Generators\Po::toFile($entries, $file . 'po'); Generators\PhpArray::toFile($entries, $file . 'php'); return $entries; }
/** * Loads translation from a Translations instance, a file on an array. * * @param Translations|string|array $translations * * @return self */ public function loadTranslations($translations) { if (is_object($translations) && $translations instanceof Translations) { $translations = PhpArray::generate($translations); } elseif (is_string($translations) && is_file($translations)) { $translations = (include $translations); } elseif (!is_array($translations)) { throw new \InvalidArgumentException('Invalid Translator: only arrays, files or instance of Translations are allowed'); } $this->addTranslations($translations); return $this; }
/** * {@parentDoc} */ public static function toString(Translations $translations) { $array = PhpArray::toArray($translations); //for a simple json translation dictionary, one domain is supported $values = current($array); // remove meta / header data if (array_key_exists('', $values)) { unset($values['']); } //map to a simple json dictionary (no plurals) return json_encode(array_filter(array_map(function ($val) { return $val[1]; }, $values))); }
public static function generate(Entries $entries, $encoded = true) { $translations = PhpArray::generate($entries); return $encoded ? json_encode($translations) : $translations; }
/** * {@parentDoc} */ public static function toString(Translations $translations) { $array = PhpArray::toArray($translations); return json_encode($array); }