コード例 #1
0
 /**
  * @param Locale $locale
  * @param Language $language
  * @return string
  */
 public function getLanguageLocalizedName(Locale $locale, Language $language)
 {
     $cacheIdentifier = 'language-labels-' . $locale->getLanguage();
     $labelsFromCache = $this->languageCache->get($cacheIdentifier);
     if ($labelsFromCache) {
         return $labelsFromCache[$language->getKey()];
     }
     try {
         $raw = $this->cldrRepository->getModelForLocale($locale)->getRawArray('localeDisplayNames/languages');
     } catch (\Exception $e) {
         return 'Problem reading data for ' . $language->getKey();
     }
     $languages = $this->getLanguages();
     $labels = array();
     /** @var Language $currentLanguage */
     foreach ($languages as $currentLanguage) {
         try {
             $key = 'language[@type="' . $currentLanguage->getKey() . '"]';
             if (is_array($raw)) {
                 if (array_key_exists($key, $raw)) {
                     $labels[$currentLanguage->getKey()] = $raw[$key];
                 } else {
                     $labels[$currentLanguage->getKey()] = $currentLanguage->getName();
                 }
             } else {
                 $labels[$currentLanguage->getKey()] = 'Nothing found for ' . $currentLanguage->getKey();
             }
         } catch (\Exception $e) {
             // not found
             // $labels[$key] = 'Nothing found for ' . $language->getKey();
         }
     }
     $this->languageCache->set($cacheIdentifier, $labels);
     return $labels[$language->getKey()];
 }
 /**
  * Generates a URI path segment for a given node taking it's language dimension into account
  *
  * @param NodeInterface $node Optional node to determine language dimension
  * @param string $text Optional text
  * @return string
  */
 public function generateUriPathSegment(NodeInterface $node = null, $text = null)
 {
     if ($node) {
         $text = $text ?: $node->getLabel() ?: $node->getName();
         $dimensions = $node->getContext()->getDimensions();
         if (array_key_exists('language', $dimensions) && $dimensions['language'] !== array()) {
             $locale = new Locale($dimensions['language'][0]);
             $language = $locale->getLanguage();
         }
     } elseif (strlen($text) === 0) {
         throw new Exception('Given text was empty.', 1457591815);
     }
     $text = $this->transliterationService->transliterate($text, isset($language) ? $language : null);
     return Transliterator::urlize($text);
 }
コード例 #3
0
 /**
  * Returns translated label ("target" tag in XLIFF) for the id given.
  * Id is compared with "id" attribute of "trans-unit" tag (see XLIFF
  * specification for details).
  *
  * @param string $transUnitId The "id" attribute of "trans-unit" tag in XLIFF
  * @param integer $pluralFormIndex Index of plural form to use (starts with 0)
  * @return mixed Translated label or FALSE on failure
  */
 public function getTargetByTransUnitId($transUnitId, $pluralFormIndex = 0)
 {
     if (!isset($this->xmlParsedData['translationUnits'][$transUnitId])) {
         $this->i18nLogger->log('No trans-unit element with the id "' . $transUnitId . '" was found in ' . $this->sourcePath . '. Either this translation has been removed or the id in the code or template referring to the translation is wrong.', LOG_DEBUG);
         return false;
     }
     if (!isset($this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex])) {
         $this->i18nLogger->log('The plural form index "' . $pluralFormIndex . '" for the trans-unit element with the id "' . $transUnitId . '" in ' . $this->sourcePath . ' is not available.', LOG_DEBUG);
         return false;
     }
     if ($this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex]['target']) {
         return $this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex]['target'];
     } elseif ($this->locale->getLanguage() === $this->xmlParsedData['sourceLocale']->getLanguage()) {
         return $this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex]['source'] ?: false;
     } else {
         $this->i18nLogger->log('The target translation was empty and the source translation language (' . $this->xmlParsedData['sourceLocale']->getLanguage() . ') does not match the current locale (' . $this->locale->getLanguage() . ') for the trans-unit element with the id "' . $transUnitId . '" in ' . $this->sourcePath, LOG_DEBUG);
         return false;
     }
 }
コード例 #4
0
 /**
  * Returns array of plural forms available for particular locale.
  *
  * @param \TYPO3\Flow\I18n\Locale $locale Locale to return plural forms for
  * @return array Plural forms' names (one, zero, two, few, many, other) available for language set in this model
  */
 public function getPluralForms(\TYPO3\Flow\I18n\Locale $locale)
 {
     if (!isset($this->rulesetsIndices[$locale->getLanguage()])) {
         return array(self::RULE_OTHER);
     }
     return array_merge(array_keys($this->rulesets[$locale->getLanguage()][$this->rulesetsIndices[$locale->getLanguage()]]), array(self::RULE_OTHER));
 }
コード例 #5
0
 /**
  * Returns array of plural forms available for particular locale.
  *
  * @param Locale $locale Locale to return plural forms for
  * @return array Plural forms' names (one, zero, two, few, many, other) available for language set in this model
  */
 public function getPluralForms(Locale $locale)
 {
     if (!isset($this->rulesetsIndices[$locale->getLanguage()])) {
         return [self::RULE_OTHER];
     }
     return array_merge(array_keys($this->rulesets[$locale->getLanguage()][$this->rulesetsIndices[$locale->getLanguage()]]), [self::RULE_OTHER]);
 }