LanguageService

This class is used to translate strings in plain PHP. For examples see Localization in PHP. A LanguageService should 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 LanguageService
Fully qualified name
\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".

lang

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

debugKey

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

getLL ( string $index)

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

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

param string $index

Label key

sL ( string $input)

splitLabel function

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

param string $input

Label key/reference

returntype

string

includeLLFile ( string $fileRef)

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

param string $fileRef

$fileRef is a file-reference

create ( string $locale)

Factory method to create a language service object.

param string $locale

the locale (= the TYPO3-internal locale given)

returntype

self

createFromUserPreferences ( TYPO3\\CMS\\Core\\Authentication\\AbstractUserAuthentication $user)
param TYPO3\\CMS\\Core\\Authentication\\AbstractUserAuthentication $user

the user

returntype

self

createFromSiteLanguage ( TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage $language)
param TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage $language

the language

returntype

self