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 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".

property lang

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

property 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.

Parameters
  • $index (string) -- 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

Parameters
  • $input (string) -- Label key/reference

Return type

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).

Parameters
  • $fileRef (string) -- $fileRef is a file-reference

create(string $locale)

Factory method to create a language service object.

Parameters
  • $locale (string) -- the locale (= the TYPO3-internal locale given)

Return type

self

createFromUserPreferences(TYPO3\\CMS\\Core\\Authentication\\AbstractUserAuthentication $user)
Parameters
  • $user (TYPO3\CMS\Core\Authentication\AbstractUserAuthentication) -- the user

Return type

self

createFromSiteLanguage(TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage $language)
Parameters
Return type

self