Neos\Flow\I18n\Translator::translateById PHP 메소드

translateById() 공개 메소드

Searches for a translation in the source as defined by $sourceName (interpretation depends on concrete translation provider used). If any arguments are provided in the $arguments array, they will be inserted to the translated string (in place of corresponding placeholders, with format defined by these placeholders). If $quantity is provided, correct plural form for provided $locale will be chosen and used to choose correct translation variant.
또한 보기: Translator::translateByOriginalLabel()
public translateById ( string $labelId, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow' ) : string
$labelId string Key to use for finding translation
$arguments array An array of values to replace placeholders with
$quantity mixed A number to find plural form for (float or int), NULL to not use plural forms
$locale Locale Locale to use (NULL for default one)
$sourceName string Name of file with translations, base path is $packageKey/Resources/Private/Locale/Translations/
$packageKey string Key of the package containing the source file
리턴 string Translated message or NULL on failure
    public function translateById($labelId, array $arguments = [], $quantity = null, Locale $locale = null, $sourceName = 'Main', $packageKey = 'Neos.Flow')
    {
        if ($locale === null) {
            $locale = $this->localizationService->getConfiguration()->getCurrentLocale();
        }
        $pluralForm = $this->getPluralForm($quantity, $locale);
        $translatedMessage = $this->translationProvider->getTranslationById($labelId, $locale, $pluralForm, $sourceName, $packageKey);
        if ($translatedMessage === false) {
            return null;
        }
        if (!empty($arguments)) {
            return $this->formatResolver->resolvePlaceholders($translatedMessage, $arguments, $locale);
        }
        return $translatedMessage;
    }

Usage Example

예제 #1
0
 /**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws FinisherException
  */
 protected function executeInternal()
 {
     $formRuntime = $this->finisherContext->getFormRuntime();
     $labelId = $this->parseOption('translation.id');
     if ($labelId !== null) {
         $locale = null;
         $localeIdentifier = $this->parseOption('translation.locale');
         if ($localeIdentifier !== null) {
             try {
                 $locale = new Locale($localeIdentifier);
             } catch (InvalidLocaleIdentifierException $exception) {
                 throw new FinisherException(sprintf('"%s" is not a valid locale identifier.', $locale), 1421325113, $exception);
             }
         }
         $messagePackageKey = $this->parseOption('translation.package');
         if ($messagePackageKey === null) {
             $renderingOptions = $formRuntime->getRenderingOptions();
             $messagePackageKey = $renderingOptions['translationPackage'];
         }
         $message = $this->translator->translateById($labelId, array(), null, $locale, $this->parseOption('translation.source'), $messagePackageKey);
     } else {
         $message = $this->parseOption('message');
     }
     $formRuntime->getResponse()->setContent($message);
 }
All Usage Examples Of Neos\Flow\I18n\Translator::translateById