‪TYPO3CMS  9.5
TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper:
TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForEmptyString

Public Member Functions

 initializeArguments ()
 

Static Public Member Functions

static string renderStatic (array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 

Static Protected Member Functions

static string null translate ($id, $extensionName, $arguments, $languageKey, $alternativeLanguageKeys)
 

Protected Attributes

bool $escapeChildren = false
 

Detailed Description

Translate a key from locallang. The files are loaded from the folder :file:Resources/Private/Language/.

Examples

Translate key

::

<f:translate key="key1" />

Value of key key1 in the current website language. Alternatively id can be used instead of key::

<f:translate id="key1" />

This will output the same as above. If both id and key are set, id will take precedence.

Keep HTML tags

::

<f:format.raw><f:translate key="htmlKey" /></f:format.raw>

Value of key htmlKey in the current website language, no :php:htmlspecialchars() applied.

Translate key from custom locallang file

::

<f:translate key="LLL:EXT:myext/Resources/Private/Language/locallang.xlf:key1" />

Value of key key1 in the current website language.

Inline notation with arguments and default value

::

{f:translate(key: 'someKey', arguments: {0: 'dog', 1: 'fox'}, default: 'default value')}

Value of key someKey in the current website language with the given arguments (“dog” and “fox”) assigned for the specified s conversions (:php:sprintf()) in the language file::

<trans-unit id="someKey" resname="someKey"> <source>Some text about a s and a s.</source> </trans-unit>

The output will be "Some text about a dog and a fox".

If the key someKey is not found in the language file, the output is “default value”.

Inline notation with extension name

::

{f:translate(key: 'someKey', extensionName: 'SomeExtensionName')}

Value of key someKey in the current website language. The locallang file of extension "some_extension_name" will be used.

Definition at line 91 of file TranslateViewHelper.php.

Member Function Documentation

◆ initializeArguments()

TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper::initializeArguments ( )

Initialize arguments.

Exceptions

Definition at line 105 of file TranslateViewHelper.php.

◆ renderStatic()

static string TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper::renderStatic ( array  $arguments,
\Closure  $renderChildrenClosure,
RenderingContextInterface  $renderingContext 
)
static

Return array element by key.

Parameters
array$arguments
\Closure$renderChildrenClosure
RenderingContextInterface$renderingContext
Exceptions
Exception
Returns
‪string

Definition at line 125 of file TranslateViewHelper.php.

◆ translate()

static string null TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper::translate (   $id,
  $extensionName,
  $arguments,
  $languageKey,
  $alternativeLanguageKeys 
)
staticprotected

Wrapper call to static LocalizationUtility

Parameters
string$id‪Translation Key
string$extensionName‪UpperCamelCased extension key (for example BlogExample)
array$arguments‪Arguments to be replaced in the resulting string
string$languageKey‪Language key to use for this translation
string[]$alternativeLanguageKeys‪Alternative language keys if no translation does exist
Returns
‪string|null

Reimplemented in TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForEmptyString.

Definition at line 169 of file TranslateViewHelper.php.

References TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate().

Member Data Documentation

◆ $escapeChildren

bool TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper::$escapeChildren = false
protected

Output is escaped already. We must not escape children, to avoid double encoding.

Definition at line 98 of file TranslateViewHelper.php.