LocalizationUtility

Localization helper which should be used to fetch localized labels.

Table of Contents

Properties

$configurationManager  : ConfigurationManagerInterface
$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.
$locallangPath  : string

Methods

translate()  : string|null
Returns the localized label of the LOCAL_LANG key, $key.
flattenTypoScriptLabelArray()  : array<string|int, mixed>
Flatten TypoScript label array; converting a hierarchical array into a flat array with the keys separated by dots.
getConfigurationManager()  : ConfigurationManagerInterface
Returns instance of the configuration manager
getCurrentSiteLanguage()  : SiteLanguage|null
Returns the currently configured "site language" if a site is configured (= resolved) in the current request.
getLanguageFilePath()  : string
Returns the default path and filename for an extension
getLanguageKeys()  : array<string|int, mixed>
Sets the currently active language keys.
getLanguageService()  : LanguageService
initializeLocalization()  : void
Loads local-language values by looking for a "locallang.xlf" file in the plugin resources directory and if found includes it.
loadTypoScriptLabels()  : void
Overwrites labels that are set via TypoScript.

Properties

$LOCAL_LANG

Local Language content

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

$LOCAL_LANG_UNSET

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

protected static 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 "".

$locallangPath

protected static string $locallangPath = 'Resources/Private/Language/'

Methods

translate()

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

public static translate(string $key[, string|null $extensionName = null ][, array<string|int, mixed> $arguments = null ][, string $languageKey = null ][, array<string|int, string> $alternativeLanguageKeys = null ]) : string|null
Parameters
$key : string

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

$extensionName : string|null = null

The name of the extension

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

The arguments of the extension, being passed over to sprintf

$languageKey : string = null

The language key or null for using the current language from the system

$alternativeLanguageKeys : array<string|int, string> = null

The alternative language keys if no translation was found.

Return values
string|null

The value from LOCAL_LANG or null if no translation was found.

flattenTypoScriptLabelArray()

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

protected static 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 static getCurrentSiteLanguage() : SiteLanguage|null
Return values
SiteLanguage|null

getLanguageFilePath()

Returns the default path and filename for an extension

protected static getLanguageFilePath(string $extensionName) : string
Parameters
$extensionName : string
Return values
string

getLanguageKeys()

Sets the currently active language keys.

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

initializeLocalization()

Loads local-language values by looking for a "locallang.xlf" file in the plugin resources directory and if found includes it.

protected static initializeLocalization(string $languageFilePath, string $languageKey, array<string|int, string> $alternativeLanguageKeys[, string $extensionName = null ]) : void

Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.xlf" file.

Parameters
$languageFilePath : string
$languageKey : string
$alternativeLanguageKeys : array<string|int, string>
$extensionName : string = null

loadTypoScriptLabels()

Overwrites labels that are set via TypoScript.

protected static loadTypoScriptLabels(string $extensionName, string $languageFilePath) : void

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

Parameters
$extensionName : string
$languageFilePath : string

        
On this page

Search results