---
title: "Translate ViewHelper <f:translate>"
manual: "Fluid ViewHelper Reference"
version: "13.4"
permalink: "https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-translate@13.4"
source: "Global/Translate.rst"
modified: "2026-09-17T09:07:45+00:00"
---

# Translate ViewHelper `<f:translate>`

ViewHelper to provide a translation for language keys ("locallang"/"LLL"). By default, the files are loaded from the folder `Resources/Private/Language/`. Placeholder substitution (like PHP's `sprintf()`) can be evaluated when provided as `arguments` attribute.

Go to the source code of this ViewHelper: [TranslateViewHelper.php (GitHub)](https://github.com/TYPO3/typo3/blob/main/typo3/sysext/fluid/Classes/ViewHelpers/TranslateViewHelper.php).

> [!NOTE]
> **See also**
>
> -   [Working with XLIFF files](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ApiOverview/Localization/XliffApi.html#xliff-api)
> -   [Multi-language Fluid templates](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ExtensionArchitecture/HowTo/Localization/Fluid.html#extension-localization-fluid)

**Table of contents**

-   [Examples](https://docs.typo3.org/permalink/t3viewhelper:examples@13.4)
-   [Arguments of the f:translate ViewHelper](https://docs.typo3.org/permalink/t3viewhelper:arguments-of-the-f-translate-viewhelper@13.4)

## Examples

### Short key - Usage in Extbase

The [key](https://docs.typo3.org/permalink/t3viewhelper:viewhelper-argument-typo3-cms-fluid-viewhelpers-translateviewhelper-key@13.4)
argument alone works only within the Extbase context.

**Fluid**

```html
<f:translate key="domain_model.title" />
```

**Language file example**

**packages/my_extension/Resources/Private/Language/locallang.xlf**

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext"
        original="EXT:my_extension/Resources/Private/Language/locallang.xlf"
        date="2020-10-18T18:20:51Z" product-name="my_extension"
    >
        <header />
        <body>
            <trans-unit id="domain_model.title">
                <source>My Model</source>
            </trans-unit>
        </body>
    </file>
</xliff>

```

Alternatively, you can use `id` instead of `key`, producing the same output.
If both `id` and `key` are set, `id` takes precedence.

If the translate ViewHelper is used with only the language key, the template
**must** be rendered within an Extbase request, usually from an Extbase
controller action. The default language file must be located in the same
extension as the Extbase controller and must be saved in the file
`Resources/Private/Language/locallang.xlf`.

### Short key and extension name

When the ViewHelper is called from outside Extbase, it is mandatory to either
pass the extension name or use the full `LLL:` reference for the key.

```html
<f:translate key="domain_model.title" extensionName="my_extension" />
```

The default language file must be saved in the extension specified in the
argument, in the file `Resources/Private/Language/locallang.xlf`.

### Full `LLL:` reference key

Using the `LLL:` language reference syntax, a language key from any `.xlf`
file can be used.

```html
<f:translate
    key="LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:domain_model.title"
/>
```

### Keeping HTML tags within translations

HTML in language labels can be used when you surround the translate ViewHelper
with a ViewHelper that allows HTML output, such as the
[Sanitize.html ViewHelper \<f:sanitize.html>](https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-sanitize-html@13.4)
in the backend or the [Format.html ViewHelper \<f:format.html>](https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-format-html@13.4)
in the frontend.

**Fluid**

**packages/my_extension/Resources/Private/Templates/Message/Show.fluid.html**

```html
<f:format.html>
    <f:translate
        key="LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:myKey"
    />
</f:format.html>
```

**Language file example**

**packages/my_extension/Resources/Private/Language/locallang.xlf**

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext"
        original="EXT:my_extension/Resources/Private/Language/locallang.xlf"
        date="2020-10-18T18:20:51Z" product-name="my_extension"
    >
        <header />
        <body>
            <trans-unit id="myKey">
                <source>
                    <![CDATA[By default, ordered and unordered lists are formatted
                    with bullets and decimals. <br>
                    By adding <code>class="list-unstyled"</code> to the ol or ul tag, it
                    is possible to structure content in list form without the
                    typical list styling.]]>
                </source>
            </trans-unit>
        </body>
    </file>
</xliff>

```

The entry in the `.xlf` language file must be surrounded by `<![CDATA[...]]>`.

> [!WARNING]
> When allowing HTML tags in translations, ensure all translators are
> educated about [Cross-site scripting (XSS)](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/Security/TypesOfThreats/Index.html#security-xss).

### Displaying translated labels with placeholders

**Fluid**

**packages/my_extension/Resources/Private/Templates/Message/Show.fluid.html**

```html
<f:translate
    key="LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:domain_model.title"
    arguments="{0: '{myVariable}'}"
/>

Or with several numbered placeholders:

<f:translate
    key="LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:domain_model.title"
    arguments="{1: '{myVariable}', 2: 'Some String'}"
/>
```

**Language file example**

**packages/my_extension/Resources/Private/Language/locallang.xlf**

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext"
        original="EXT:my_extension/Resources/Private/Language/locallang.xlf"
        date="2020-10-18T18:20:51Z" product-name="my_extension"
    >
        <header />
        <body>
            <label index="domain_model.title">Title of: %s</label>
            <trans-unit id="domain_model.description">
                <source>Some text about a %1$s and a %2$s.</source>
            </trans-unit>
        </body>
    </file>
</xliff>

```

The placeholder `%s` is used to insert dynamic values, passed as the parameter
[arguments](https://docs.typo3.org/permalink/t3viewhelper:viewhelper-argument-typo3-cms-fluid-viewhelpers-translateviewhelper-arguments@13.4)
to the translate ViewHelper. If `%s` appears multiple times, it references
subsequent array entries in order.

To avoid dependency on order, use indexed placeholders like `%1$s`. This
explicitly refers to the first value and ensures that it is treated as a string
(`$s`). This method is based on PHP’s
`vsprintf function <https://www.php.net/manual/en/function.vsprintf.php>`,
which allows for more flexible and readable formatting.

### Inline notation with arguments and default value

Like all other ViewHelpers, the translate ViewHelper can be used with the
[Inline syntax](https://docs.typo3.org/other/typo3fluid/fluid/main/en-us/Syntax/ViewHelpers.html#viewhelper-inline-notation).

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

This is especially useful if you want to pass the translated label to another
ViewHelper, for example, as the `alt` parameter of an image:

```html
<f:image src="EXT:my_extension/Resources/Public/icons/Edit.svg"
    alt="{f:translate(key: 'icons.edit', default: 'Edit')}"
/>
```

### The translation ViewHelper in console/CLI context

The translation ViewHelper determines the target language based on the current
frontend or backend request.

If you are rendering your template from a console/CLI context, for example,
when you [Send emails with FluidEmail](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ApiOverview/Mail/Index.html#mail-fluid-email),
use the argument [languageKey](https://docs.typo3.org/permalink/t3viewhelper:viewhelper-argument-typo3-cms-fluid-viewhelpers-translateviewhelper-languagekey@13.4)
to specify the desired language for the ViewHelper:

**packages/my_extension/Resources/Private/Templates/Email/Salutation.fluid.html**

```html
Salutation in Danish:
<f:translate
    key="LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:salutation"
    languageKey="da"
/>

Salutation in English:
<f:translate
    key="LLL:EXT:my_extension/Resources/Private/Language/my_locallang.xlf:salutation"
    languageKey="default"
/>
```

## Arguments of the f:translate ViewHelper

-   **arguments**

    -   *Type:* array

    Arguments to be replaced in the resulting string

-   **default**

    -   *Type:* string

    If the given locallang key could not be found, this value is used. If this argument is not set, child nodes will be used to render the default

-   **extensionName**

    -   *Type:* string

    UpperCamelCased extension key (for example BlogExample)

-   **id**

    -   *Type:* string

    Translation ID. Same as key.

-   **key**

    -   *Type:* string

    Translation Key

-   **languageKey**

    -   *Type:* string

    Language key ("da" for example) or "default" to use. Also a Locale object is possible. If empty, use current locale from the request.
