---
title: "LanguageService"
manual: "TYPO3 Explained"
version: "13.4"
permalink: "https://docs.typo3.org/permalink/t3coreapi:languageservice-api@13.4"
source: "ApiOverview/Localization/LocalizationApi/LanguageService.rst"
rendered: "2026-09-23T17:02:48+00:00"
---

# LanguageService {#languageservice-api}

This class is used to translate strings in plain PHP. For examples
see [Localization in PHP](https://docs.typo3.org/permalink/t3coreapi:extension-localization-php@13.4). A
`\TYPO3\CMS\Core\Localization\LanguageService` **should not**
be created directly, therefore its constructor is internal. Create a
`\TYPO3\CMS\Core\Localization\LanguageService` with the
[LanguageServiceFactory](https://docs.typo3.org/permalink/t3coreapi:languageservicefactory-api@13.4).

In the backend context a `LanguageService` is stored in the global
variable `$GLOBALS['LANG']`.
In the frontend a `\TYPO3\CMS\Core\Localization\LanguageService` can
be accessed via the contentObject:

**EXT:my_extension/Classes/Controller/ExampleController.php (not Extbase)**

```php
<?php

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;

final class ExampleController
{
  private ServerRequestInterface $request;

  public function __construct(
    private readonly LanguageServiceFactory $languageServiceFactory,
  ) {}

  public function processAction(
    string $content,
    array $configurations,
    ServerRequestInterface $request,
  ): string {
    $this->request = $request;

    // ...
    $content .=  $this->getTranslatedLabel(
      'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:labels.exampleLabel',
    );
    // ...

    return $content;
  }

  private function getTranslatedLabel(string $key): string
  {
    $language = $this->request->getAttribute('language')
        ?? $this->request->getAttribute('site')->getDefaultLanguage();
    $languageService = $this->languageServiceFactory
        ->createFromSiteLanguage($language);

    return $languageService->sL($key);
  }
}

```

In CLI context `$GLOBALS['LANG']` is also not available and has to be
instantiated manually.

-   **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 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:

    ```php
    $languageService = GeneralUtility::makeInstance(LanguageServiceFactory::class)
        ->createFromUserPreferences($GLOBALS['BE_USER']);
    ```

    -   **public lang**

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

    -   **sL(?string $input)**

        Main and most often used method.

        Resolve strings like these:

        ```php
        'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'
        ```

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

        Only the plain string contents of a language key, like "Record title: %s" are returned.
        Placeholder interpolation must be performed separately, for example via `sprintf()`, like
        `LocalizationUtility::translate()` does internally (which should only be used in Extbase
        context)

        Example:
        Label is defined in `EXT:my_extension/Resources/Private/Language/locallang.xlf` as:

        ```php
        <trans-unit id="downloaded_times">
            <source>downloaded %d times from %s locations</source>
        </trans-unit>
        ```

        The following code example assumes `$this->request` to hold the current request object.
        There are several ways to create the LanguageService using the Factory, depending on the
        context. Please adjust this example to your use case:

        ```php
        $language = $this->request->getAttribute('language');
        $languageService =
          GeneralUtility::makeInstance(LanguageServiceFactory::class)
          ->createFromSiteLanguage($language);
        $label = sprintf(
             $languageService->sL(
                 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:downloaded_times'
             ),
             27,
             'several'
        );
        ```

        This will result in `$label` to contain `'downloaded 27 times from several locations'`.

        -   *param $input:* Label key/reference

        *Returns:* `string`

    -   **overrideLabels(string $fileRef, array $labels)**

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

        -   *param $fileRef:* the fileRef
        -   *param $labels:* the labels

    -   **getLocale()**

        *Returns:* `?TYPO3CMSCoreLocalizationLocale`
