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

$configurationManager  : ConfigurationManagerInterface
$languageKey  : string
Key of the language to use
$languageServiceFactory  : LanguageServiceFactory
$locales  : Locales
$runtimeCache  : FrontendInterface

Methods

__construct()  : mixed
getLanguage()  : string
setLanguage()  : mixed
translate()  : mixed
Returns the localized label of the LOCAL_LANG key, $key.
translateFinisherOption()  : string
translateFormElementError()  : string
translateFormElementValue()  : string|array
translateToAllBackendLanguages()  : array
translateValuesRecursive()  : array
Recursively translate values.
buildLanguageService()  : LanguageService
flattenTypoScriptLabelArray()  : array
Flatten TypoScript label array; converting a hierarchical array into a flat array with the keys separated by dots.
getCurrentSiteLanguage()  : SiteLanguage|null
Returns the currently configured "site language" if a site is configured (= resolved) in the current request.
initializeLocalization()  : LanguageService
isEmptyTranslatedValue()  : bool
Check if given translated value is considered "empty".
loadTypoScriptLabels()  : array
Overwrites labels that are set via TypoScript.
processTranslationChain()  : string|null
setLanguageKeys()  : void
Sets the currently active language keys.
sortArrayWithIntegerKeysDescending()  : array
If the array contains numerical keys only, sort it in descending order

Properties

$languageKey

Key of the language to use

protected string $languageKey = ''

Methods

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|null $arguments = null ][, string|null $locallangPathAndFilename = null ][, string|null $language = 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
$language : 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

buildLanguageService()

protected buildLanguageService(string $languageKey, mixed $languageFilePath) : LanguageService
Parameters
$languageKey : string
$languageFilePath : mixed
Return values
LanguageService

flattenTypoScriptLabelArray()

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

protected flattenTypoScriptLabelArray(array $labelValues[, string $parentKey = '' ]) : array

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

Parameters
$labelValues : array

Hierarchical array of labels

$parentKey : string = ''

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

Return values
array —

flattened array of labels.

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

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

loadTypoScriptLabels()

Overwrites labels that are set via TypoScript.

protected loadTypoScriptLabels() : array

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

Return values
array

processTranslationChain()

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

setLanguageKeys()

Sets the currently active language keys.

protected setLanguageKeys(string|null $language) : void
Parameters
$language : string|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