/** * Loads a language file * * After laoding the file it's content will be flattened. Then the result will replace all keys already existing in * object string repository. * * @param string $filename * * @throws AppException */ public function load(string $filename) { if (!file_exists($filename)) { throw new AppException(sprintf('Languagefile "%s" does not exist.'), $filename); } $loaded = (include $filename); if ($loaded) { $array = new Flatten($loaded); $array->setPreserveFlaggedArraysFlag(true); $this->strings = array_replace($this->strings, $array->flatten()); } }
/** * Parses an array of key/value structured strings, flattens it with the glue and adds it to the a language storage * * @param array $language * The array with language strings * @param string $storage_name * The name of the language storage to place the srings in * @param string $glue * Optional glue which should be used in flattening process */ public function parseLanguageArray(array $language, string $storage_name, string $glue = '.') { $toolbox = new Flatten($language); $toolbox->setPreserveFlaggedArraysFlag(true); $toolbox->setGlue($glue); $language = $toolbox->flatten(); if (!empty($language) && !isset($this->storage->{$storage_name})) { $this->storage->{$storage_name} = new LanguageStorage(); } foreach ($language as $key => $val) { $this->storage->{$storage_name}->{$key} = $val; } }