/** * Returns translated string found under the $labelId. * * 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 $arguments * contains exactly one numeric element, it is automatically used as the * $quantity. * * @param string $labelId Key to use for finding translation * @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 \TYPO3\FLOW3\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 message or $labelId on failure * @api * @see \TYPO3\FLOW3\I18n\Translator::translateByOriginalLabel() */ public function translateById($labelId, array $arguments = array(), $quantity = NULL, \TYPO3\FLOW3\I18n\Locale $locale = NULL, $sourceName = 'Main', $packageKey = 'TYPO3.FLOW3') { if ($locale === NULL) { $locale = $this->localizationService->getConfiguration()->getCurrentLocale(); } $pluralForm = $this->getPluralForm($quantity, $arguments, $locale); $translatedMessage = $this->translationProvider->getTranslationById($labelId, $locale, $pluralForm, $sourceName, $packageKey); if ($translatedMessage === FALSE) { return $labelId; } elseif ($arguments !== array()) { return $this->formatResolver->resolvePlaceholders($translatedMessage, $arguments, $locale); } return $translatedMessage; }
/** * @test * @dataProvider placeholderAndDateValues */ public function formatResolverWithDatetimeReplacesCorrectValues($stringWithPlaceholders, $arguments, $locale, $expected) { $result = $this->formatResolver->resolvePlaceholders($stringWithPlaceholders, $arguments, $locale); $this->assertEquals($expected, $result); }