Neos\Flow\I18n\Translator::translateByOriginalLabel PHP Method

translateByOriginalLabel() public method

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. If no $locale is provided, default system locale will be used.
public translateByOriginalLabel ( string $originalLabel, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow' ) : string
$originalLabel string Untranslated message
$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
return string Translated $originalLabel or $originalLabel itself on failure
    public function translateByOriginalLabel($originalLabel, 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->getTranslationByOriginalLabel($originalLabel, $locale, $pluralForm, $sourceName, $packageKey);
        if ($translatedMessage === false) {
            $translatedMessage = $originalLabel;
        }
        if (!empty($arguments)) {
            $translatedMessage = $this->formatResolver->resolvePlaceholders($translatedMessage, $arguments, $locale);
        }
        return $translatedMessage;
    }

Usage Example

 /**
  * Renders the translated label.
  * Replaces all placeholders with corresponding values if they exist in the
  * translated label.
  *
  * @param string $id Id to use for finding translation (trans-unit id in XLIFF)
  * @param string $value If $key is not specified or could not be resolved, this value is used. If this argument is not set, child nodes will be used to render the default
  * @param array $arguments Numerically indexed array of values to be inserted into placeholders
  * @param string $source Name of file with translations (use / as a directory separator)
  * @param string $package Target package key. If not set, the current package key will be used
  * @param mixed $quantity A number to find plural form for (float or int), NULL to not use plural forms
  * @param string $locale An identifier of locale to use (NULL for use the default locale)
  * @return string Translated label or source label / ID key
  * @throws ViewHelperException
  */
 public function render($id = null, $value = null, array $arguments = array(), $source = 'Main', $package = null, $quantity = null, $locale = null)
 {
     $localeObject = null;
     if ($locale !== null) {
         try {
             $localeObject = new Locale($locale);
         } catch (InvalidLocaleIdentifierException $e) {
             throw new ViewHelperException(sprintf('"%s" is not a valid locale identifier.', $locale), 1279815885);
         }
     }
     if ($package === null) {
         $request = $this->renderingContext->getControllerContext()->getRequest();
         if ($request instanceof ActionRequest) {
             $package = $request->getControllerPackageKey();
         }
         if ($package === null) {
             throw new ViewHelperException('The current package key can\'t be resolved. Make sure to initialize the Fluid view with a proper ActionRequest and/or specify the "package" argument when using the f:translate ViewHelper', 1416832309);
         }
     }
     $originalLabel = $value === null ? $this->renderChildren() : $value;
     if ($id === null) {
         return (string) $this->translator->translateByOriginalLabel($originalLabel, $arguments, $quantity, $localeObject, $source, $package);
     }
     $translation = $this->translator->translateById($id, $arguments, $quantity, $localeObject, $source, $package);
     if ($translation !== null) {
         return (string) $translation;
     }
     if ($originalLabel !== null) {
         return $originalLabel;
     }
     return (string) $id;
 }
All Usage Examples Of Neos\Flow\I18n\Translator::translateByOriginalLabel