TranslationService implements SingletonInterface

Advanced translations This class is subjected to change.

Do NOT subclass

Scope: frontend / backend

Internal

Table of Contents

Interfaces

SingletonInterface
"empty" interface for singletons (marker interface pattern)

Properties

$alternativeLanguageKeys  : array<string|int, mixed>
Pointer to alternative fall-back language to use
$configurationManager  : ConfigurationManagerInterface
$languageKey  : string
Key of the language to use
$LOCAL_LANG  : array<string|int, mixed>
Local Language content
$LOCAL_LANG_UNSET  : array<string|int, mixed>
Contains those LL keys, which have been set to (empty) in TypoScript.

Methods

__construct()  : mixed
getInstance()  : self
Return TranslationService as singleton
getLanguage()  : string
setLanguage()  : mixed
translate()  : mixed
Returns the localized label of the LOCAL_LANG key, $key.
translateFinisherOption()  : string
translateFormElementError()  : string
translateFormElementValue()  : string|array<string|int, mixed>
translateToAllBackendLanguages()  : array<string|int, mixed>
translateValuesRecursive()  : array<string|int, mixed>
Recursively translate values.
flattenTypoScriptLabelArray()  : array<string|int, mixed>
Flatten TypoScript label array; converting a hierarchical array into a flat array with the keys separated by dots.
getAllTypo3BackendLanguages()  : array<string|int, mixed>
getCurrentSiteLanguage()  : SiteLanguage|null
Returns the currently configured "site language" if a site is configured (= resolved) in the current request.
getLanguageService()  : LanguageService
initializeLocalization()  : mixed
loadTypoScriptLabels()  : mixed
Overwrites labels that are set via TypoScript.
processTranslationChain()  : string|null
setLanguageKeys()  : mixed
Sets the currently active language keys.
sortArrayWithIntegerKeysDescending()  : array<string|int, mixed>
If the array contains numerical keys only, sort it in descending order

Properties

$alternativeLanguageKeys

Pointer to alternative fall-back language to use

protected array<string|int, mixed> $alternativeLanguageKeys = []

$languageKey

Key of the language to use

protected string $languageKey

$LOCAL_LANG

Local Language content

protected array<string|int, mixed> $LOCAL_LANG = []

$LOCAL_LANG_UNSET

Contains those LL keys, which have been set to (empty) in TypoScript.

protected array<string|int, mixed> $LOCAL_LANG_UNSET = []

This is necessary, as we cannot distinguish between a nonexisting translation and a label that has been cleared by TS. In both cases ['key'][0]['target'] is "".

Methods

getInstance()

Return TranslationService as singleton

public static getInstance() : self
Deprecated

will be removed in TYPO3 v12.0. Use Dependency Injection or GeneralUtility::makeInstance() if DI is not possible.

Internal
Return values
self

getLanguage()

public getLanguage() : string
Internal
Return values
string

setLanguage()

public setLanguage(string $languageKey) : mixed
Parameters
$languageKey : string
Internal

translate()

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

public translate(mixed $key[, array<string|int, mixed> $arguments = null ][, string $locallangPathAndFilename = null ][, string $language = null ][, mixed $defaultValue = '' ]) : mixed
Parameters
$key : mixed

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

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

the arguments of the extension, being passed over to vsprintf

$locallangPathAndFilename : string = null
$language : string = 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<string|int, mixed> $renderingOptions = [] ]) : string
Parameters
$formRuntime : FormRuntime
$finisherIdentifier : string
$optionKey : string
$optionValue : string
$renderingOptions : array<string|int, mixed> = []
Tags
throws
InvalidArgumentException
Return values
string

translateFormElementError()

public translateFormElementError(RootRenderableInterface $element, int $code, array<string|int, mixed> $arguments, string $defaultValue, FormRuntime $formRuntime) : string
Parameters
$element : RootRenderableInterface
$code : int
$arguments : array<string|int, mixed>
$defaultValue : string
$formRuntime : FormRuntime
Internal
Tags
throws
InvalidArgumentException
Return values
string

translateFormElementValue()

public translateFormElementValue(RootRenderableInterface $element, array<string|int, mixed> $propertyParts, FormRuntime $formRuntime) : string|array<string|int, mixed>
Parameters
$element : RootRenderableInterface
$propertyParts : array<string|int, mixed>
$formRuntime : FormRuntime
Internal
Tags
throws
InvalidArgumentException
Return values
string|array<string|int, mixed>

translateToAllBackendLanguages()

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

the modified array

translateValuesRecursive()

Recursively translate values.

public translateValuesRecursive(array<string|int, mixed> $array[, array<string|int, mixed> $translationFiles = [] ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
$translationFiles : array<string|int, mixed> = []
Internal
Return values
array<string|int, mixed>

the modified array

flattenTypoScriptLabelArray()

Flatten TypoScript label array; converting a hierarchical array into a flat array with the keys separated by dots.

protected flattenTypoScriptLabelArray(array<string|int, mixed> $labelValues[, string $parentKey = '' ]) : array<string|int, mixed>

Example Input: array('k1' => array('subkey1' => 'val1')) Example Output: array('k1.subkey1' => 'val1')

Parameters
$labelValues : array<string|int, mixed>

Hierarchical array of labels

$parentKey : string = ''

the name of the parent key in the recursion; is only needed for recursion.

Return values
array<string|int, mixed>

flattened array of labels.

getAllTypo3BackendLanguages()

protected getAllTypo3BackendLanguages() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCurrentSiteLanguage()

Returns the currently configured "site language" if a site is configured (= resolved) in the current request.

protected getCurrentSiteLanguage() : SiteLanguage|null
Return values
SiteLanguage|null

initializeLocalization()

protected initializeLocalization(string $locallangPathAndFilename) : mixed
Parameters
$locallangPathAndFilename : string

loadTypoScriptLabels()

Overwrites labels that are set via TypoScript.

protected loadTypoScriptLabels() : mixed

TS locallang labels have to be configured like: plugin.tx_form._LOCAL_LANG.languageKey.key = value

processTranslationChain()

protected processTranslationChain(array<string|int, mixed> $translationKeyChain[, string $language = null ][, array<string|int, mixed> $arguments = null ]) : string|null
Parameters
$translationKeyChain : array<string|int, mixed>
$language : string = null
$arguments : array<string|int, mixed> = null
Return values
string|null

setLanguageKeys()

Sets the currently active language keys.

protected setLanguageKeys() : mixed

sortArrayWithIntegerKeysDescending()

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

protected sortArrayWithIntegerKeysDescending(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results