LanguageService

This class is used to translate strings in plain PHP. For examples see Localization in PHP. A LanguageServiceshould not be created directly, therefore its constructor is internal. Create a LanguageService with the LanguageServiceFactory.

In the backend context a LanguageService is stored in the global variable $GLOBALS['LANG'].

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 to 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. Do not rely on $GLOBAL['LANG'] in frontend, as it is only available under 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".

Further usages on setting up your own LanguageService in BE:

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

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

sL ( string $input)

Main and most often used method.

Resolve strings like these:

'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'
Copied!

This looks up the given .xlf file path in the 'core' extension for label labels.depth_0

param string $input

Label key/reference

returntype

string

overrideLabels ( string $fileRef, array $labels)

Define custom labels which can be overridden for a given file. This is typically the case for TypoScript plugins.

param string $fileRef

the fileRef

param array $labels

the labels

getLocale ( )
returntype

TYPO3\CMS\Core\Localization\Locale