TranslateViewHelper extends AbstractViewHelper

ViewHelper

This class is the implementation of a Fluid ViewHelper.

View this class in the TYPO3 ViewHelper reference: <f:translate>

FinalYes

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, using PHP sprintf() notation <https://www.php.net/sprintf>__ in the language file::

Some text about a %s and a %s.

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

If the key someKey is not found in the language file, the output is :html:default value.

As in PHP's :php:sprintf() you can order placeholders (:php:Second %2$s, first %1$s) or use specific types like :php:A padded number: %'.09d, returning 000000123 for a number passed as 123. See the sprintf_ PHP Documentation for more information on possible formatting.

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.

.. _sprintf: https://www.php.net/sprintf

Table of Contents

Properties

$escapeChildren  : bool
Output is escaped already. We must not escape children, to avoid double encoding.

Methods

initializeArguments()  : void
render()  : string
Return array element by key.
getUsedLocale()  : Locale|string|null
handleDefaultValue()  : string
Ensure that a string is returned, if the underlying logic returns null, or cannot handle a translation

Properties

$escapeChildren

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

protected bool $escapeChildren = false

Methods

initializeArguments()

public initializeArguments() : void

render()

Return array element by key.

public render() : string
Tags
throws
Exception
throws
RuntimeException
Return values
string

getUsedLocale()

protected static getUsedLocale(Locale|string|null $languageKey, ServerRequestInterface|null $request) : Locale|string|null
Parameters
$languageKey : Locale|string|null
$request : ServerRequestInterface|null
Return values
Locale|string|null

handleDefaultValue()

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

protected static handleDefaultValue(string $default, array<string|int, mixed>|null $translateArguments) : string
Parameters
$default : string
$translateArguments : array<string|int, mixed>|null
Return values
string

        
On this page

Search results