‪TYPO3CMS  ‪main
TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper:

Public Member Functions

 initializeArguments ()
 

Static Public Member Functions

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

Static Protected Member Functions

static handleDefaultValue (string $default, ?array $translateArguments)
 
static getUsedLocale (Locale|string|null $languageKey, ?ServerRequestInterface $request)
 

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="key1" extensionName="MyExt"/>

or

::

<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 106 of file TranslateViewHelper.php.

Member Function Documentation

◆ getUsedLocale()

static TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper::getUsedLocale ( Locale|string|null  $languageKey,
?ServerRequestInterface  $request 
)
staticprotected

◆ handleDefaultValue()

static TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper::handleDefaultValue ( string  $default,
?array  $translateArguments 
)
staticprotected

Ensure that a string is returned, if the underlying logic returns null, or cannot handle a translation

Definition at line 190 of file TranslateViewHelper.php.

Referenced by TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper\renderStatic().

◆ initializeArguments()

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

Definition at line 115 of file TranslateViewHelper.php.

◆ renderStatic()

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

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 113 of file TranslateViewHelper.php.