Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
LanguageService
This class is used to translate strings in plain PHP. For examples
see Localization in PHP. A Language
should not
be created directly, therefore its constructor is internal. Create a
Language
with the LanguageServiceFactory.
In the backend context a Language
is stored in the global
variable $GLOBALS
.
- class LanguageService
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Localization\ Language Service
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".
- 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