TranslateViewHelper extends AbstractViewHelper uses CompileWithRenderStatic

ViewHelper

This class is the implementation of a Fluid ViewHelper.

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

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::

Some text about a %s and a %s.

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.

Table of Contents

Properties

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

Methods

initializeArguments()  : mixed
Initialize arguments.
renderStatic()  : string
Return array element by key.
translate()  : string|null
Wrapper call to static LocalizationUtility

Properties

$escapeChildren

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

protected bool $escapeChildren = false

Methods

initializeArguments()

Initialize arguments.

public initializeArguments() : mixed
Tags
throws
Exception

renderStatic()

Return array element by key.

public static renderStatic(array<string|int, mixed> $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) : string
Parameters
$arguments : array<string|int, mixed>
$renderChildrenClosure : Closure
$renderingContext : RenderingContextInterface
Tags
throws
Exception
Return values
string

translate()

Wrapper call to static LocalizationUtility

protected static translate(string $id, string $extensionName, array<string|int, mixed> $arguments, string $languageKey, array<string|int, string> $alternativeLanguageKeys) : string|null
Parameters
$id : string

Translation Key

$extensionName : string

UpperCamelCased extension key (for example BlogExample)

$arguments : array<string|int, mixed>

Arguments to be replaced in the resulting string

$languageKey : string

Language key to use for this translation

$alternativeLanguageKeys : array<string|int, string>

Alternative language keys if no translation does exist

Return values
string|null

        
On this page

Search results