TranslatorInterface

Interface for translation services.

This interface provides a clean abstraction for translating labels in TYPO3. It uses ICU MessageFormat style where pluralization and other complex formatting logic is embedded in the message string itself, not in the API signature.

Example usage:

// Simple translation
$translator->translate('button.save', 'backend.messages');

// Translation with arguments (sprintf-style placeholders)
$translator->translate('record.count', 'backend.messages', [5]);

// ICU MessageFormat style for plurals (message: "{count, plural, one {# item} other {# items}}")
$translator->translate('items.count', 'backend.messages+intl-icu', ['count' => 5]);
Tags
see
https://unicode-org.github.io/icu/userguide/format_parse/messages/

ICU MessageFormat

Table of Contents

Methods

label()  : string|Stringable|null
Translate a label by its full reference string.
translate()  : string|Stringable|null
Translate a label by its identifier and domain.

Methods

label()

Translate a label by its full reference string.

public label(string $reference[, array<string|int, mixed> $arguments = [] ][, string|null $default = null ][, Locale|string|null $locale = null ]) : string|Stringable|null

Resolves TYPO3 label reference strings in the formats:

'core.messages:labels.depth_0'
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'
'EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'

The LLL: prefix is optional and stripped before resolution.

Example usage:

// Simple reference
$translator->label('myext.messages:button.save');

// Simple reference (discouraged with file reference)
$translator->label('LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:button.save');

// With arguments
$translator->label('core.messages:record.count', [5]);

// With default value
$translator->label('core.messages:missing.key', [], 'Fallback text');
Parameters
$reference : string

The label reference string (with or without LLL: prefix)

$arguments : array<string|int, mixed> = []

Optional arguments for placeholder replacement

$default : string|null = null

Optional default value returned when the label is not found

$locale : Locale|string|null = null

Optional locale override. If null, uses the service's configured locale.

Return values
string|Stringable|null

The translated string, the default value, or null if the label was not found

translate()

Translate a label by its identifier and domain.

public translate(string $id, string $domain[, array<string|int, mixed> $arguments = [] ][, string|null $default = null ][, Locale|string|null $locale = null ]) : string|Stringable|null
Parameters
$id : string

The label identifier/key

$domain : string

The translation domain (file reference like 'EXT:core/Resources/Private/Language/locallang.xlf' or semantic domain like 'core.messages'). For ICU MessageFormat, suffix with '+intl-icu'.

$arguments : array<string|int, mixed> = []

Optional arguments for placeholder replacement. For sprintf-style messages, pass indexed values. For ICU messages, pass named values (e.g., ['count' => 5]).

$default : string|null = null

Optional default value

$locale : Locale|string|null = null

Optional locale override. If null, uses the service's configured locale.

Return values
string|Stringable|null

The translated string, or null if the label was not found


        
On this page

Search results