/** * Translates the message given as $originalLabel. * * 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. * * @param string $originalLabel Untranslated message * @param array $arguments An array of values to replace placeholders with * @param float|int|null $quantity A number to find plural form for (float or int), NULL to not use plural forms * @param \TYPO3\Flow\I18n\Locale $locale Locale to use (NULL for default one) * @param string $sourceName Name of file with translations, base path is $packageKey/Resources/Private/Locale/Translations/ * @param string $packageKey Key of the package containing the source file * @return string Translated $originalLabel or $originalLabel itself on failure * @api */ public function translateByOriginalLabel($originalLabel, array $arguments = array(), $quantity = null, \TYPO3\Flow\I18n\Locale $locale = null, $sourceName = 'Main', $packageKey = 'TYPO3.Flow') { $translatedMessage = $this->translationProvider->getTranslationByOriginalLabel($originalLabel, $locale, $quantity, $sourceName, $packageKey); if ($translatedMessage === false) { $translatedMessage = $originalLabel; } if (!empty($arguments)) { $translatedMessage = $this->formatResolver->resolvePlaceholders($translatedMessage, $arguments, $locale); } return $translatedMessage; }
/** * Translates the message given as $originalLabel. * * 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. * * @param string $originalLabel Untranslated message * @param array $arguments An array of values to replace placeholders with * @param mixed $quantity A number to find plural form for (float or int), NULL to not use plural forms * @param Locale $locale Locale to use (NULL for default one) * @param string $sourceName Name of file with translations, base path is $packageKey/Resources/Private/Locale/Translations/ * @param string $packageKey Key of the package containing the source file * @return string Translated $originalLabel or $originalLabel itself on failure * @api */ public function translateByOriginalLabel($originalLabel, array $arguments = [], $quantity = null, Locale $locale = null, $sourceName = 'Main', $packageKey = 'TYPO3.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; }