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

Breadcrumb

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

function ConfigurableLanguage::createFromLangcode

Creates a configurable language object from a langcode.

Parameters

string $langcode: The language code to use to create the object.

Return value

$this

See also

\Drupal\Core\Language\LanguageManager::getStandardLanguageList()

2 calls to ConfigurableLanguage::createFromLangcode()
ImportForm::submitForm in core/modules/locale/src/Form/ImportForm.php
Form submission handler.
install_download_additional_translations_operations in core/includes/install.core.inc
Prepares the system for import and downloads additional translations.

File

core/modules/language/src/Entity/ConfigurableLanguage.php, line 280

Class

ConfigurableLanguage
Defines the ConfigurableLanguage entity.

Namespace

Drupal\language\Entity

Code

public static function createFromLangcode($langcode) {
    $standard_languages = LanguageManager::getStandardLanguageList();
    if (!isset($standard_languages[$langcode])) {
        // Drupal does not know about this language, so we set its values with the
        // best guess. The user will be able to edit afterwards.
        return static::create([
            'id' => $langcode,
            'label' => $langcode,
        ]);
    }
    else {
        // A known predefined language, details will be filled in properly.
        return static::create([
            'id' => $langcode,
            'label' => $standard_languages[$langcode][0],
            'direction' => $standard_languages[$langcode][2] ?? static::DIRECTION_LTR,
        ]);
    }
}

API Navigation

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