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

Breadcrumb

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

function Request::getLanguages

Gets a list of languages acceptable by the client browser ordered in the user browser preferences.

Return value

string[]

1 call to Request::getLanguages()
Request::getPreferredLanguage in vendor/symfony/http-foundation/Request.php
Returns the preferred language.

File

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

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getLanguages() : array {
    if (null !== $this->languages) {
        return $this->languages;
    }
    $languages = AcceptHeader::fromString($this->headers
        ->get('Accept-Language'))
        ->all();
    $this->languages = [];
    foreach ($languages as $acceptHeaderItem) {
        $lang = $acceptHeaderItem->getValue();
        $this->languages[] = self::formatLocale($lang);
    }
    $this->languages = array_unique($this->languages);
    return $this->languages;
}

API Navigation

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