‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Localization\LanguageService Class Reference

Public Member Functions

 __construct (protected Locales $locales, protected readonly LocalizationFactory $localizationFactory, protected readonly FrontendInterface $runtimeCache)
 init (Locale|string $languageKey)
 sL ($input)
array includeLLFile (string $fileRef)
 translateLabel (array|string $input, string $fallback)
array< string, getLabelsFromResource(string $fileRef):array { $labelArray=[];$labelsFromFile=$this-> readLLfile ($fileRef)
 overrideLabels (string $fileRef, array $labels)
 getLocale ()

Public Attributes

string $lang = 'default'
foreach($labelsFromFile['default'] as $key=> $value) return $labelArray

Protected Member Functions

string getLLL (string $index, array $localLanguage)
array readLLfile (string $fileRef)

Protected Attributes

Locale $locale = null
array $labels = []
array $overrideLabels = []

Private Member Functions

 getTypo3LanguageKey ()

Detailed Description

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)

Definition at line 45 of file LanguageService.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Localization\LanguageService::__construct ( protected Locales  $locales,
protected readonly LocalizationFactory  $localizationFactory,
protected readonly FrontendInterface  $runtimeCache 

use LanguageServiceFactory instead

Definition at line 67 of file LanguageService.php.

Member Function Documentation

◆ getLLL()

string TYPO3\CMS\Core\Localization\LanguageService::getLLL ( string  $index,
array  $localLanguage 

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

string$index‪Label key
array$localLanguage‪$LOCAL_LANG array to get label key from

Definition at line 102 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\$lang.

Referenced by TYPO3\CMS\Core\Localization\LanguageService\sL().

◆ getLocale()

TYPO3\CMS\Core\Localization\LanguageService::getLocale ( )

◆ getTypo3LanguageKey()

TYPO3\CMS\Core\Localization\LanguageService::getTypo3LanguageKey ( )

◆ includeLLFile()

array TYPO3\CMS\Core\Localization\LanguageService::includeLLFile ( string  $fileRef)

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

string$fileRef‪$fileRef is a file-reference
‪array returns the loaded label file

do not rely on this method as it is only used for internal purposes in TYPO3 v13.0.

Definition at line 175 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\readLLfile().

◆ init()

TYPO3\CMS\Core\Localization\LanguageService::init ( Locale|string  $languageKey)

Initializes the language to fetch XLF labels for.

$languageService = GeneralUtility::makeInstance(LanguageServiceFactory::class)

Definition at line 85 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\getTypo3LanguageKey().

◆ overrideLabels()

TYPO3\CMS\Core\Localization\LanguageService::overrideLabels ( string  $fileRef,
array  $labels 

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

Definition at line 264 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\$labels, and TYPO3\CMS\Core\Localization\LanguageService\getTypo3LanguageKey().

Referenced by TYPO3\CMS\Core\Localization\LanguageService\sL().

◆ readLLfile() [1/2]

array<string, getLabelsFromResource(string $fileRef): array { $labelArray = []; $labelsFromFile = $this-> TYPO3\CMS\Core\Localization\LanguageService::readLLfile (   $fileRef)

Load all labels from a resource/file and returns them in a translated fashion.

‪array<string, string>

not part of TYPO3 Core API for the time being.

Referenced by TYPO3\CMS\Core\Localization\LanguageService\includeLLFile(), and TYPO3\CMS\Core\Localization\LanguageService\sL().

◆ readLLfile() [2/2]

array TYPO3\CMS\Core\Localization\LanguageService::readLLfile ( string  $fileRef)

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

string$fileRef‪Input is a file-reference to be a 'local_lang' file containing a $LOCAL_LANG array
‪array value of $LOCAL_LANG found in the included file, empty if none found

Definition at line 221 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\$locale, and TYPO3\CMS\Core\Localization\LanguageService\getTypo3LanguageKey().

◆ sL()

TYPO3\CMS\Core\Localization\LanguageService::sL (   $input)

Main and most often used method.

Resolve strings like these:


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

string$input‪Label key/reference

Definition at line 131 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\getLLL(), TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath(), TYPO3\CMS\Core\Localization\LanguageService\overrideLabels(), and TYPO3\CMS\Core\Localization\LanguageService\readLLfile().

Referenced by TYPO3\CMS\Core\FormProtection\FormProtectionFactory\getMessageClosure(), and TYPO3\CMS\Core\Localization\LanguageService\translateLabel().

◆ translateLabel()

TYPO3\CMS\Core\Localization\LanguageService::translateLabel ( array|string  $input,
string  $fallback 

Translates prepared labels which are handed in, and also uses the fallback if no language is given. This is common in situations such as page TSconfig where labels or references to labels are used.

not part of TYPO3 Core API for the time being.

Definition at line 189 of file LanguageService.php.

References TYPO3\CMS\Core\Localization\LanguageService\sL().

Member Data Documentation

◆ $labelArray

foreach ( $labelsFromFile[ 'default'] as $key=> $value) return TYPO3\CMS\Core\Localization\LanguageService::$labelArray

Definition at line 212 of file LanguageService.php.

◆ $labels

array TYPO3\CMS\Core\Localization\LanguageService::$labels = []

◆ $lang

string TYPO3\CMS\Core\Localization\LanguageService::$lang = 'default'

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

Definition at line 50 of file LanguageService.php.

Referenced by TYPO3\CMS\Core\Localization\LanguageService\getLLL().

◆ $locale

Locale TYPO3\CMS\Core\Localization\LanguageService::$locale = null

◆ $overrideLabels

array TYPO3\CMS\Core\Localization\LanguageService::$overrideLabels = []

Definition at line 62 of file LanguageService.php.

Definition: ext_localconf.php:25