TranslationService implements SingletonInterface
Advanced translations This class is subjected to change.
Do NOT subclass
Scope: frontend / backend
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<string|int, mixed>
- translateToAllBackendLanguages() : array<string|int, mixed>
- translateValuesRecursive() : array<string|int, mixed>
- Recursively translate values.
- buildLanguageService() : LanguageService
- flattenTypoScriptLabelArray() : array<string|int, mixed>
- 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<string|int, mixed>
- Overwrites labels that are set via TypoScript.
- processTranslationChain() : string|null
- setLanguageKeys() : void
- Sets the currently active language keys.
- sortArrayWithIntegerKeysDescending() : array<string|int, mixed>
- If the array contains numerical keys only, sort it in descending order
Properties
$configurationManager read-only
protected
ConfigurationManagerInterface
$configurationManager
$languageKey
Key of the language to use
protected
string
$languageKey
= ''
$languageServiceFactory read-only
protected
LanguageServiceFactory
$languageServiceFactory
$locales read-only
protected
Locales
$locales
$runtimeCache read-only
protected
FrontendInterface
$runtimeCache
Methods
__construct()
public
__construct(ConfigurationManagerInterface $configurationManager, LanguageServiceFactory $languageServiceFactory, FrontendInterface $runtimeCache, Locales $locales) : mixed
Parameters
- $configurationManager : ConfigurationManagerInterface
- $languageServiceFactory : LanguageServiceFactory
- $runtimeCache : FrontendInterface
- $locales : Locales
getLanguage()
public
getLanguage() : string
Return values
stringsetLanguage()
public
setLanguage(string $languageKey) : mixed
Parameters
- $languageKey : string
translate()
Returns the localized label of the LOCAL_LANG key, $key.
public
translate(mixed $key[, array<string|int, mixed>|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<string|int, mixed>|null = null
-
the arguments of the extension, being passed over to vsprintf
- $locallangPathAndFilename : string|null = null
- $language : 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<string|int, mixed> $renderingOptions = [] ]) : string
Parameters
- $formRuntime : FormRuntime
- $finisherIdentifier : string
- $optionKey : string
- $optionValue : string
- $renderingOptions : array<string|int, mixed> = []
Tags
Return values
stringtranslateFormElementError()
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
Tags
Return values
stringtranslateFormElementValue()
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
Tags
Return values
string|array<string|int, mixed>translateToAllBackendLanguages()
public
translateToAllBackendLanguages(string $key[, array<string|int, mixed>|null $arguments = null ][, array<string|int, mixed> $translationFiles = [] ]) : array<string|int, mixed>
Parameters
- $key : string
- $arguments : array<string|int, mixed>|null = null
- $translationFiles : array<string|int, mixed> = []
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> = []
Return values
array<string|int, mixed> —the modified array
buildLanguageService()
protected
buildLanguageService(string $languageKey, mixed $languageFilePath) : LanguageService
Parameters
- $languageKey : string
- $languageFilePath : mixed
Return values
LanguageServiceflattenTypoScriptLabelArray()
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.
getCurrentSiteLanguage()
Returns the currently configured "site language" if a site is configured (= resolved) in the current request.
protected
getCurrentSiteLanguage() : SiteLanguage|null
Return values
SiteLanguage|nullinitializeLocalization()
protected
initializeLocalization(string $locallangPathAndFilename) : LanguageService
Parameters
- $locallangPathAndFilename : string
Return values
LanguageServiceisEmptyTranslatedValue()
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
boolloadTypoScriptLabels()
Overwrites labels that are set via TypoScript.
protected
loadTypoScriptLabels() : array<string|int, mixed>
TS labels have to be configured like: plugin.tx_myextension._LOCAL_LANG.languageKey.key = value
Return values
array<string|int, mixed>processTranslationChain()
protected
processTranslationChain(array<string|int, mixed> $translationKeyChain[, string|null $language = null ][, array<string|int, mixed>|null $arguments = null ]) : string|null
Parameters
- $translationKeyChain : array<string|int, mixed>
- $language : string|null = null
- $arguments : array<string|int, mixed>|null = null
Return values
string|nullsetLanguageKeys()
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<string|int, mixed> $array) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>