Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Request.php

function Request::formatLocale

Strips the locale to only keep the canonicalized language value.

Depending on the $locale value, this method can return values like :

  • language_Script_REGION: "fr_Latn_FR", "zh_Hans_TW"
  • language_Script: "fr_Latn", "zh_Hans"
  • language_REGION: "fr_FR", "zh_TW"
  • language: "fr", "zh"

Invalid locale values are returned as is.

See also

https://wikipedia.org/wiki/IETF_language_tag

https://datatracker.ietf.org/doc/html/rfc5646

2 calls to Request::formatLocale()
Request::getLanguages in vendor/symfony/http-foundation/Request.php
Gets a list of languages acceptable by the client browser ordered in the user browser preferences.
Request::getPreferredLanguage in vendor/symfony/http-foundation/Request.php
Returns the preferred language.

File

vendor/symfony/http-foundation/Request.php, line 1608

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

private static function formatLocale(string $locale) : string {
    [
        $language,
        $script,
        $region,
    ] = self::getLanguageComponents($locale);
    return implode('_', array_filter([
        $language,
        $script,
        $region,
    ]));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal