diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index a7c6663..0147f12 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -187,7 +187,7 @@ function _language_admin_common_controls(&$form, $language = NULL) { } $form['name'] = array( '#type' => 'textfield', - '#title' => t('Language name'), + '#title' => t('Language name in English'), '#maxlength' => 64, '#default_value' => @$language->name, '#required' => TRUE, diff --git a/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php b/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php index 4172e96..5991f9e 100644 --- a/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php +++ b/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php @@ -10,6 +10,8 @@ use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\Core\Language\LanguageManager; use Drupal\language\LanguageInterface; /** @@ -76,4 +78,15 @@ class Language extends ConfigEntityBase implements LanguageInterface { */ public $locked = FALSE; + /** + * {@inheritdoc} + */ + public function preSave(EntityStorageControllerInterface $storage_controller) { + parent::preSave($storage_controller); + // Languages are picked from a predefined list which is given in English. + // For the uncommon case of custom languages the label should be given in + // English. + $this->langcode = 'en'; + } + } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php index 4bce384..f970bdd 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php @@ -51,6 +51,9 @@ function testLanguageConfiguration() { $this->drupalPost('admin/config/regional/language/add', $edit, 'Add language'); $this->assertText('French'); $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Langcode for Languages is always 'en'. + $language = $this->container->get('config.factory')->get('language.entity.fr')->get(); + $this->assertEqual($language['langcode'], 'en'); // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); @@ -100,6 +103,16 @@ function testLanguageConfiguration() { ); $this->drupalPost(NULL, $edit, t('Save configuration')); $this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.'); + + // Remove English language and add a new Language to check if langcode of + // Language entity is 'en'. + $this->assert(language_delete('en'), 'Deleted English language.'); + $edit = array( + 'predefined_langcode' => 'de', + ); + $this->drupalPost('admin/config/regional/language/add', $edit, 'Add language'); + $language = $this->container->get('config.factory')->get('language.entity.de')->get(); + $this->assertEqual($language['langcode'], 'en'); } /** diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php index f5875af..ff8086b 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\language\Tests\LanguageCustomConfigurationTest. + * Contains \Drupal\language\Tests\LanguageCustomConfigurationTest. */ namespace Drupal\language\Tests; @@ -47,7 +47,7 @@ public function testLanguageConfiguration() { $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); // Test validation on missing values. $this->assertText(t('!name field is required.', array('!name' => t('Language code')))); - $this->assertText(t('!name field is required.', array('!name' => t('Language name')))); + $this->assertText(t('!name field is required.', array('!name' => t('Language name in English')))); $empty_language = new Language(); $this->assertFieldChecked('edit-direction-' . $empty_language->direction, 'Consistent usage of language direction.'); $this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.'); @@ -61,7 +61,7 @@ public function testLanguageConfiguration() { ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); $this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code')))); - $this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name')))); + $this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name in English')))); $this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.'); // Test validation of existing language values.