/** * @test */ public function modelIsReturnedCorrectlyForSingleFile() { file_put_contents('vfs://Foo/Bar.xml', ''); $result = $this->repository->getModel('Bar'); $this->assertAttributeContains('vfs://Foo/Bar.xml', 'sourcePaths', $result); $result = $this->repository->getModel('NoSuchFile'); $this->assertEquals(FALSE, $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; } }
/** * 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); }
/** * 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; } }