LocalizationUtility

Localization helper which should be used to fetch localized labels.

Table of Contents

Properties

$locallangPath  : string

Methods

translate()  : string|null
Returns the localized label of the LOCAL_LANG key, $key.
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.
getLanguageFilePath()  : string
Returns the default path and filename for an extension
getLocale()  : Locale
Resolves the currently active locale.
getRuntimeCache()  : FrontendInterface
initializeLocalization()  : LanguageService
Loads local-language values by looking for a "locallang.xlf" file in the plugin resources directory and if found includes it.
loadTypoScriptLabels()  : array<string|int, mixed>
Overwrites labels that are set via TypoScript.

Properties

$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>|null $arguments = null ][, Locale|string|null $languageKey = 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 = null

The arguments of the extension, being passed over to sprintf

$languageKey : Locale|string|null = null

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

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.

getLanguageFilePath()

Returns the default path and filename for an extension

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

getLocale()

Resolves the currently active locale.

protected static getLocale(Locale|string|null $localeOrLanguageKey) : Locale

Using the Locales factory, as it handles dependencies (e.g. "de-AT" falls back to "de").

Parameters
$localeOrLanguageKey : Locale|string|null
Return values
Locale

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, Locale $locale, string|null $extensionName) : LanguageService

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

Parameters
$languageFilePath : string
$locale : Locale
$extensionName : string|null
Return values
LanguageService

loadTypoScriptLabels()

Overwrites labels that are set via TypoScript.

protected static loadTypoScriptLabels(string $extensionName) : array<string|int, mixed>

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

Parameters
$extensionName : string
Return values
array<string|int, mixed>

        
On this page

Search results