This method finds a group of CLDR files within $directoryPath dir,
for particular Locale. Returned model represents whole locale-chain.
For example, for locale en_GB, returned model could represent 'en_GB',
'en', and 'root' CLDR files.
Returns FALSE when $directoryPath doesn't point to existing directory.
public getModelForLocale ( |
||
$locale | A locale | |
$directoryPath | string | Relative path to existing CLDR directory which contains one file per locale (see 'main' directory in CLDR for example) |
return | A CldrModel instance or NULL on failure |
/** * @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; }