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 : array<string|int, array<string|int, string>>
- $languageDependencies : array<string|int, mixed>
- 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<string|int, mixed>
- 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<string|int, mixed>
- 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<string|int, mixed>
- 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'
$labels
protected
array<string|int, array<string|int, string>>
$labels
= []
$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<string|int, mixed>
$languageDependencies
= []
$locales
protected
Locales
$locales
$localizationFactory
protected
LocalizationFactory
$localizationFactory
$runtimeCache
protected
FrontendInterface
$runtimeCache
Methods
__construct()
public
__construct(Locales $locales, LocalizationFactory $localizationFactory, FrontendInterface $runtimeCache) : mixed
Parameters
- $locales : Locales
- $localizationFactory : LocalizationFactory
- $runtimeCache : FrontendInterface
use one of the factory methods instead
create()
Factory method to create a language service object.
public
static create(string $locale) : static
since TYPO3 v11.3, will be removed in v12.0
Parameters
- $locale : string
-
the locale (= the TYPO3-internal locale given)
Return values
staticcreateFromSiteLanguage()
public
static createFromSiteLanguage(SiteLanguage $language) : self
since TYPO3 v11.3, will be removed in v12.0
Parameters
- $language : SiteLanguage
Return values
selfcreateFromUserPreferences()
public
static createFromUserPreferences(AbstractUserAuthentication|null $user) : self
since TYPO3 v11.3, will be removed in v12.0
Parameters
- $user : AbstractUserAuthentication|null
Return values
selfgetLL()
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
stringincludeLLFile()
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<string|int, mixed>
Parameters
- $fileRef : string
-
$fileRef is a file-reference
Return values
array<string|int, mixed> —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)
use one of the factory methods instead
Tags
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
stringdebugLL()
Debugs localization key.
protected
debugLL(string $value) : string
Parameters
- $value : string
-
value to debug
Return values
stringgetLLL()
Returns the label with key $index from the $LOCAL_LANG array used as the second argument
protected
getLLL(string $index, array<string|int, mixed> $localLanguage) : string
Parameters
- $index : string
-
Label key
- $localLanguage : array<string|int, mixed>
-
$LOCAL_LANG array to get label key from
Return values
stringincludeLanguageFileRaw()
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<string|int, mixed>
Parameters
- $fileRef : string
-
$fileRef is a file-reference
Return values
array<string|int, mixed>readLLfile()
Includes a locallang file and returns the $LOCAL_LANG array found inside.
protected
readLLfile(string $fileRef) : array<string|int, mixed>
Parameters
- $fileRef : string
-
Input is a file-reference to be a 'local_lang' file containing a $LOCAL_LANG array
Return values
array<string|int, mixed> —value of $LOCAL_LANG found in the included file, empty if non found