TranslationService

Advanced translations This class is subjected to change.

Do NOT subclass

Scope: frontend / backend

Internal
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
translateFormElementError()  : string
translateFormElementValue()  : array|string|null
translateToAllBackendLanguages()  : array
translateValuesRecursive()  : array
Recursively translate values.
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 = ''
Internal
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

translateToAllBackendLanguages()

public translateToAllBackendLanguages(string $key[, array|null $arguments = null ][, array $translationFiles = [] ]) : array
Parameters
$key : string
$arguments : array|null = null
$translationFiles : array = []
Internal
Return values
array —

the modified array

translateValuesRecursive()

Recursively translate values.

public translateValuesRecursive(array $array[, array $translationFiles = [] ]) : array
Parameters
$array : array
$translationFiles : array = []
Internal
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

Search results