TranslationService

class \TYPO3\CMS\Form\Service\TranslationService

Advanced translations This class is subjected to change.

Do NOT subclass

Scope: frontend / backend

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Properties

$keychainBuilder  : FormTranslationKeychainBuilder
$languageServiceFactory  : LanguageServiceFactory
$locales  : Locales

Methods

__construct()  : mixed
translate()  : mixed
Returns the localized label of the LOCAL_LANG key, $key.
translateFinisherOption()  : string
translateFormEditorDefinitions()  : array
Recursively translate form editor definitions.
translateFormElementError()  : string
translateFormElementValue()  : array|string|null
translateFormEngineFinisherOptions()  : array<string, array<string, mixed>>
Translate finisher options rendered as FormEngine elements.
translateSingleValue()  : mixed
Translate a single value.
translateToAllBackendLanguages()  : array
translateValuesRecursive()  : array
Recursively translate values of given array.
isEmptyTranslatedValue()  : bool
Check if given translated value is considered "empty".
processTranslationChain()  : string|Stringable|null
sortArrayWithIntegerKeysDescending()  : array
If the array contains numerical keys only, sort it in descending order

Properties

Methods

translate()

Returns the localized label of the LOCAL_LANG key, $key.

public translate(mixed $key[, array|null $arguments = null ][, string|null $locallangPathAndFilename = null ][, Locale|string|null $locale = null ][, mixed $defaultValue = '' ]) : mixed

Parameters

$key : mixed

The key from the LOCAL_LANG array for which to return the value.

$arguments : array|null = null

the arguments of the extension, being passed over to vsprintf

$locallangPathAndFilename : string|null = null
$locale : Locale|string|null = null
$defaultValue : mixed = ''

Return values

mixed —

The value from LOCAL_LANG or $defaultValue if no translation was found.

translateFinisherOption()

public translateFinisherOption(FormRuntime $formRuntime, string $finisherIdentifier, string $optionKey, string $optionValue[, array $renderingOptions = [] ]) : string

Parameters

$formRuntime : FormRuntime
$finisherIdentifier : string
$optionKey : string
$optionValue : string
$renderingOptions : array = []

Tags

throws
InvalidArgumentException

Return values

string

translateFormEditorDefinitions()

Recursively translate form editor definitions.

public translateFormEditorDefinitions(array $formEditorDefinitions[, array<int, string> $translationFiles = [] ]) : array

Works like translateValuesRecursive(), but keeps the values of select options untranslated. These are technical values which are stored in form definitions, only their labels are meant to be translated.

Parameters

$formEditorDefinitions : array

The form editor definitions to be translated

$translationFiles : array<int, string> = []

List of translation files

Return values

array —

The translated form editor definitions

translateFormEngineFinisherOptions()

Translate finisher options rendered as FormEngine elements.

public translateFormEngineFinisherOptions(array<string, array<string, mixed>> $elements[, array<int, string> $translationFiles = [] ]) : array<string, array<string, mixed>>

Performs translation of all suitable finisher options being rendered as FormEngine elements. Rendering of those elements happens in FlexForm overrides.

Since only a subset of FormEngine config can be translated in a meaningful way, the element config cannot be just traversed and translated. It's rather required to check each config path against a list of translatable config paths. This list consists of the following configs:

  • Element label
  • Element description
  • Element placeholder (config.placeholder)
  • Element title (used in sections, e.g. recipients in email finishers)
  • Labels of element items (used for multi-value elements, e.g. checkboxes or select elements)
  • Labels of item groups (config.itemGroups, used for select elements)

Parameters

$elements : array<string, array<string, mixed>>

Elements and their appropriate FormEngine config to be translated

$translationFiles : array<int, string> = []

List of translation files

Return values

array<string, array<string, mixed>> —

Translated elements

translateSingleValue()

Translate a single value.

public translateSingleValue(mixed $value[, array<int, string> $translationFiles = [] ]) : mixed

Parameters

$value : mixed

The value to be translated

$translationFiles : array<int, string> = []

List of translation files

Return values

mixed —

The translated value

translateToAllBackendLanguages()

public translateToAllBackendLanguages(string $key[, array|null $arguments = null ][, array $translationFiles = [] ]) : array

Parameters

$key : string
$arguments : array|null = null
$translationFiles : array = []

Return values

array —

the modified array

translateValuesRecursive()

Recursively translate values of given array.

public translateValuesRecursive(array $array[, array $translationFiles = [] ]) : array

Parameters

$array : array

The array with values to be recursively translated

$translationFiles : array = []

List of translation files

Return values

array —

The modified array

isEmptyTranslatedValue()

Check if given translated value is considered "empty".

protected isEmptyTranslatedValue(mixed $translatedValue) : bool

A translated value is considered "empty" if it's either NULL or an empty string. This helper method exists to perform a less strict check than the native empty() function, because it is too strict in terms of supported translated values. For example, the value "0" is valid, whereas empty() would handle it as "empty" and therefore invalid.

Parameters

$translatedValue : mixed

Return values

bool

processTranslationChain()

protected processTranslationChain(array $translationKeyChain[, Locale|string|null $locale = null ][, array|null $arguments = null ]) : string|Stringable|null

Parameters

$translationKeyChain : array
$locale : Locale|string|null = null
$arguments : array|null = null

Return values

string|Stringable|null

sortArrayWithIntegerKeysDescending()

If the array contains numerical keys only, sort it in descending order

protected sortArrayWithIntegerKeysDescending(array $array) : array

Parameters

$array : array

Return values

array
On this page