class Language

An object containing the information for an interface language.

@todo To keep backwards compatibility with stdClass, we currently use public scopes for the Language class's variables. We will change these to full get/set functions in a follow-up issue: http://drupal.org/node/1512424

Hierarchy

Expanded class hierarchy of Language

See also

language_default()

35 files declare their use of Language
ArgumentLanguageTest.php in drupal/core/modules/views/lib/Drupal/views/Tests/Language/ArgumentLanguageTest.php
Contains Drupal\views\Tests\Language\ArgumentLanguageTest.
bootstrap.inc in drupal/core/includes/bootstrap.inc
Functions that need to be loaded on every Drupal request.
DateTimeTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php
Definition of Drupal\system\Tests\System\DateTimeTest.
DrupalJsonldNormalizerTest.php in drupal/core/modules/jsonld/lib/Drupal/jsonld/Tests/DrupalJsonldNormalizerTest.php
Definition of Drupal\jsonld\Tests\DrupalJsonldNormalizerTest.
Entity.php in drupal/core/lib/Drupal/Core/Entity/Entity.php
Definition of Drupal\Core\Entity\Entity.

... See full list

34 string references to 'Language'
comment_views_data in drupal/core/modules/comment/comment.views.inc
Implements hook_views_data().
EntityTestFormController::form in drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php
Overrides Drupal\Core\Entity\EntityFormController::form().
LanguageBrowserDetectionUnitTest::getInfo in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php
LanguageConfigurationElementTest::getInfo in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php
LanguageConfigurationTest::getInfo in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php

... See full list

File

drupal/core/lib/Drupal/Core/Language/Language.php, line 19
Definition of Drupal\Core\Language\Language.

Namespace

Drupal\Core\Language
View source
class Language {

  // Properties within the Language are set up as the default language.
  public $name = '';
  public $langcode = '';
  public $direction = LANGUAGE_LTR;
  public $weight = 0;
  public $default = FALSE;
  public $method_id = NULL;
  public $locked = FALSE;

  /**
   * Language constructor builds the default language object.
   *
   * @param array $options
   *   The properties used to construct the language.
   */
  public function __construct(array $options = array()) {

    // Set all the provided properties for the language.
    foreach ($options as $name => $value) {
      $this->{$name} = $value;
    }

    // If some options were not set, set sane defaults of a predefined language.
    if (!isset($options['name']) || !isset($options['direction'])) {
      include_once DRUPAL_ROOT . '/core/includes/standard.inc';
      $predefined = standard_language_list();
      if (isset($predefined[$this->langcode])) {
        if (!isset($options['name'])) {
          $this->name = $predefined[$this->langcode][0];
        }
        if (!isset($options['direction']) && isset($predefined[$this->langcode][2])) {
          $this->direction = $predefined[$this->langcode][2];
        }
      }
    }
  }

  /**
   * Extend $this with properties from the given object.
   *
   * @todo Remove this function once $GLOBALS['language'] is gone.
   */
  public function extend($obj) {
    $vars = get_object_vars($obj);
    foreach ($vars as $var => $value) {
      $this->{$var} = $value;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Language::$default public property
Language::$direction public property
Language::$langcode public property
Language::$locked public property
Language::$method_id public property
Language::$name public property
Language::$weight public property
Language::extend public function Extend $this with properties from the given object.
Language::__construct public function Language constructor builds the default language object.