/** * @test */ public function modelIsReturnedCorrectlyForLocaleImplicatingChaining() { $localeImplementingChaining = new \TYPO3\Flow\I18n\Locale('de_DE'); $cldrModel = $this->cldrRepository->getModelForLocale($localeImplementingChaining); $this->assertAttributeContains(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/root.xml')), 'sourcePaths', $cldrModel); $this->assertAttributeContains(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->cldrBasePath, 'main/de_DE.xml')), 'sourcePaths', $cldrModel); $this->assertAttributeContains(\TYPO3\Flow\Utility\Files::concatenatePaths(array($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 the localized name of a country or - if no localization was found - the country code * * @param $countryCode * @return string */ public function getTerritoryNameForIsoCode($countryCode) { // get the localized country names from the CLDR data $i18nConfiguration = $this->i18nService->getConfiguration(); $cldrModel = $this->cldrRepository->getModel('main/' . $i18nConfiguration->getCurrentLocale()->getLanguage()); $countries = $cldrModel->findNodesWithinPath('localeDisplayNames/territories', 'territory'); if (array_key_exists('territory[@type="' . strtoupper($countryCode) . '"]', $countries)) { return $countries['territory[@type="' . strtoupper($countryCode) . '"]']; } else { return $countryCode; } }
/** * 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 \TYPO3\Flow\I18n\Locale $locale * @return array Symbols array */ public function getLocalizedSymbolsForLocale(\TYPO3\Flow\I18n\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'); }
/** * Override this method in your custom FormElements if needed * * @return void */ public function initializeFormElement() { // the not localized country codes and names $selectOptions = $this->getProperties()['options']; // get the localized country names from the CLDR data $i18nConfiguration = $this->i18nService->getConfiguration(); $cldrModel = $this->cldrRepository->getModel('main/' . $i18nConfiguration->getCurrentLocale()->getLanguage()); $countries = $cldrModel->findNodesWithinPath('localeDisplayNames/territories', 'territory'); // if the country is found in the CLDR data, use the localized name $localizedSelectOptions = array(); foreach ($selectOptions as $countryCode => $countryName) { if (array_key_exists('territory[@type="' . strtoupper($countryCode) . '"]', $countries)) { $localizedSelectOptions[$countryCode] = $countries['territory[@type="' . strtoupper($countryCode) . '"]']; } else { $localizedSelectOptions[$countryCode] = $countryName; } } $this->setProperty('options', $localizedSelectOptions); }
/** * Returns literals array for locale provided. * * If array was not generated earlier, it will be generated and cached. * * @param \TYPO3\Flow\I18n\Locale $locale * @return array An array with localized literals */ public function getLocalizedLiteralsForLocale(\TYPO3\Flow\I18n\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; }
/** * Get an array of all values in the CLDR where the key is the type attribute * * @param string $path The xpath to select values from * @return array|boolean */ protected function getKeyValues($path) { $defaultLocale = $this->detector->detectLocaleFromLocaleTag('en'); $model = $this->cldrRepository->getModelForLocale($defaultLocale); $data = $model->getRawArray($path); if ($data === FALSE) { return FALSE; } $filteredData = array(); foreach ($data as $nodeString => $children) { if (CldrModel::getAttributeValue($nodeString, 'alt') === FALSE) { $key = CldrModel::getAttributeValue($nodeString, 'type'); $filteredData[$key] = $children; } } return $filteredData; }
/** * 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 \TYPO3\Flow\I18n\Cldr\Reader\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 = array(); 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; } }