LanguageService

class \TYPO3\CMS\Core\Localization\LanguageService

Main API to fetch labels from XLF (label files) based on the current system language of TYPO3. It is able to resolve references to files + their pointers to the proper language. If you see something about "LLL", this class does the trick for you. It is not related for language handling of content, but rather of labels for plugins.

Usually this is injected into $GLOBALS['LANG'] when in backend or CLI context, and populated by the current backend user. Don't rely on $GLOBAL['LANG'] in frontend, as it is only available in certain circumstances! In Frontend, this is also used to translate "labels", see TypoScriptFrontendController->sL() for that.

As TYPO3 internally does not match the proper ISO locale standard, the "locale" here is actually a list of supported language keys, (see Locales class), whereas "english" has the language key "default".

Table of Contents

Properties

$debugKey  : bool
If TRUE, will show the key/location of labels in the backend.
$lang  : string
This is set to the language that is currently running for the user
$labels  : string[][]
$languageDependencies  : array
List of language dependencies for actual language. This is used for local variants of a language that depend on their "main" language, like Brazilian Portuguese or Canadian French.
$locales  : Locales
$localizationFactory  : LocalizationFactory
$runtimeCache  : FrontendInterface

Methods

__construct()  : mixed
create()  : static
Factory method to create a language service object.
createFromSiteLanguage()  : self
createFromUserPreferences()  : self
getLL()  : string
Returns the label with key $index from the globally loaded $LOCAL_LANG array.
includeLLFile()  : array
Includes locallang file (and possibly additional localized version if configured for) Read language labels will be merged with $LOCAL_LANG (if $setGlobal = TRUE).
init()  : mixed
Initializes the language to fetch XLF labels for.
loadSingleTableDescription()  : mixed
Loading $TCA_DESCR[$table]['columns'] with content from locallang files as defined in $TCA_DESCR[$table]['refs'] $TCA_DESCR is a global var
sL()  : string
splitLabel function
debugLL()  : string
Debugs localization key.
getLLL()  : string
Returns the label with key $index from the $LOCAL_LANG array used as the second argument
includeLanguageFileRaw()  : array
Includes a locallang file (and possibly additional localized version if configured for), and then puts everything into "default", so "default" is kept as fallback
readLLfile()  : array
Includes a locallang file and returns the $LOCAL_LANG array found inside.

Properties

$debugKey

If TRUE, will show the key/location of labels in the backend.

public bool $debugKey = false

$lang

This is set to the language that is currently running for the user

public string $lang = 'default'

$languageDependencies

List of language dependencies for actual language. This is used for local variants of a language that depend on their "main" language, like Brazilian Portuguese or Canadian French.

protected array $languageDependencies = []

Methods

create()

Factory method to create a language service object.

public static create(string $locale) : static

Deprecated

since TYPO3 v11.3, will be removed in v12.0

Parameters

$locale : string

the locale (= the TYPO3-internal locale given)

Return values

static

createFromSiteLanguage()

public static createFromSiteLanguage(SiteLanguage $language) : self

Deprecated

since TYPO3 v11.3, will be removed in v12.0

Parameters

$language : SiteLanguage

Return values

self

getLL()

Returns the label with key $index from the globally loaded $LOCAL_LANG array.

public getLL(string $index) : string

Mostly used from modules with only one LOCAL_LANG file loaded into the global space.

Parameters

$index : string

Label key

Return values

string

includeLLFile()

Includes locallang file (and possibly additional localized version if configured for) Read language labels will be merged with $LOCAL_LANG (if $setGlobal = TRUE).

public includeLLFile(string $fileRef) : array

Parameters

$fileRef : string

$fileRef is a file-reference

Return values

array —

returns the loaded label file

init()

Initializes the language to fetch XLF labels for.

public init(string $languageKey) : mixed

$languageService = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);

Parameters

$languageKey : string

The language key (two character string from backend users profile)

Tags

throws
RuntimeException

loadSingleTableDescription()

Loading $TCA_DESCR[$table]['columns'] with content from locallang files as defined in $TCA_DESCR[$table]['refs'] $TCA_DESCR is a global var

public loadSingleTableDescription(string $table) : mixed

Parameters

$table : string

Table name found as key in global array $TCA_DESCR

sL()

splitLabel function

public sL(string $input) : string

All translations are based on $LOCAL_LANG variables. 'language-splitted' labels can therefore refer to a local-lang file + index. Refer to 'Inside TYPO3' for more details

Parameters

$input : string

Label key/reference

Return values

string

debugLL()

Debugs localization key.

protected debugLL(string $value) : string

Parameters

$value : string

value to debug

Return values

string

getLLL()

Returns the label with key $index from the $LOCAL_LANG array used as the second argument

protected getLLL(string $index, array $localLanguage) : string

Parameters

$index : string

Label key

$localLanguage : array

$LOCAL_LANG array to get label key from

Return values

string

includeLanguageFileRaw()

Includes a locallang file (and possibly additional localized version if configured for), and then puts everything into "default", so "default" is kept as fallback

protected includeLanguageFileRaw(string $fileRef) : array

Parameters

$fileRef : string

$fileRef is a file-reference

Return values

array

readLLfile()

Includes a locallang file and returns the $LOCAL_LANG array found inside.

protected readLLfile(string $fileRef) : array

Parameters

$fileRef : string

Input is a file-reference to be a 'local_lang' file containing a $LOCAL_LANG array

Return values

array —

value of $LOCAL_LANG found in the included file, empty if non found

On this page