/** * @test */ public function modelIsReturnedCorrectlyForLocaleImplicatingChaining() { $localeImplementingChaining = new I18n\Locale('de_DE'); $cldrModel = $this->cldrRepository->getModelForLocale($localeImplementingChaining); $this->assertAttributeContains(Files::concatenatePaths([$this->cldrBasePath, 'main/root.xml']), 'sourcePaths', $cldrModel); $this->assertAttributeContains(Files::concatenatePaths([$this->cldrBasePath, 'main/de_DE.xml']), 'sourcePaths', $cldrModel); $this->assertAttributeContains(Files::concatenatePaths([$this->cldrBasePath, 'main/de.xml']), 'sourcePaths', $cldrModel); }
/** * @test */ public function modelIsReturnedCorrectlyForGroupOfFiles() { mkdir('vfs://Foo/Directory'); file_put_contents('vfs://Foo/Directory/en.xml', ''); $result = $this->repository->getModelForLocale($this->dummyLocale, 'Directory'); $this->assertAttributeContains('vfs://Foo/Directory/root.xml', 'sourcePaths', $result); $this->assertAttributeContains('vfs://Foo/Directory/en.xml', 'sourcePaths', $result); $result = $this->repository->getModelForLocale($this->dummyLocale, 'NoSuchDirectory'); $this->assertEquals(null, $result); }
/** * Returns symbols array for provided locale. * * Symbols are elements defined in tag symbols from CLDR. They define * localized versions of various number-related elements, like decimal * separator, group separator or minus sign. * * Symbols arrays for every requested locale are cached. * * @param Locale $locale * @return array Symbols array */ public function getLocalizedSymbolsForLocale(Locale $locale) { if (isset($this->localizedSymbols[(string) $locale])) { return $this->localizedSymbols[(string) $locale]; } $model = $this->cldrRepository->getModelForLocale($locale); return $this->localizedSymbols[(string) $locale] = $model->getRawArray('numbers/symbols'); }
/** * Returns literals array for locale provided. * * If array was not generated earlier, it will be generated and cached. * * @param Locale $locale * @return array An array with localized literals */ public function getLocalizedLiteralsForLocale(Locale $locale) { if (isset($this->localizedLiterals[(string) $locale])) { return $this->localizedLiterals[(string) $locale]; } $model = $this->cldrRepository->getModelForLocale($locale); $localizedLiterals['months'] = $this->parseLocalizedLiterals($model, 'month'); $localizedLiterals['days'] = $this->parseLocalizedLiterals($model, 'day'); $localizedLiterals['quarters'] = $this->parseLocalizedLiterals($model, 'quarter'); $localizedLiterals['dayPeriods'] = $this->parseLocalizedLiterals($model, 'dayPeriod'); $localizedLiterals['eras'] = $this->parseLocalizedEras($model); return $this->localizedLiterals[(string) $locale] = $localizedLiterals; }
/** * Generates an internal representation of plural rules which can be found * in plurals.xml CLDR file. * * The properties $rulesets and $rulesetsIndices should be empty before * running this method. * * @return void * @see PluralsReader::$rulesets */ protected function generateRulesets() { $model = $this->cldrRepository->getModel('supplemental/plurals'); $pluralRulesSet = $model->getRawArray('plurals'); $index = 0; foreach ($pluralRulesSet as $pluralRulesNodeString => $pluralRules) { $localeLanguages = $model->getAttributeValue($pluralRulesNodeString, 'locales'); foreach (explode(' ', $localeLanguages) as $localeLanguage) { $this->rulesetsIndices[$localeLanguage] = $index; } if (is_array($pluralRules)) { $ruleset = []; foreach ($pluralRules as $pluralRuleNodeString => $pluralRule) { $pluralForm = $model->getAttributeValue($pluralRuleNodeString, 'count'); $ruleset[$pluralForm] = $this->parseRule($pluralRule); } foreach (explode(' ', $localeLanguages) as $localeLanguage) { $this->rulesets[$localeLanguage][$index] = $ruleset; } } ++$index; } }