diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 8e16464..e228c7f 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -267,36 +267,34 @@ public function setNegotiator(LanguageNegotiatorInterface $negotiator) { * {@inheritdoc} */ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { - if (!isset($this->languages)) { - // Prepopulate the language list with the default language to keep things - // working even if we have no configuration. - $default = $this->getDefaultLanguage(); - $this->languages = array($default->id => $default); - - // Retrieve the list of languages defined in configuration. - $prefix = 'language.entity.'; - $config_ids = $this->configFactory->listAll($prefix); - - // Instantiate languages from config objects. - $weight = 0; - foreach ($this->configFactory->loadMultiple($config_ids) as $config) { - $data = $config->get(); - $langcode = $data['id']; - // Initialize default property so callers have an easy reference and can - // save the same object without data loss. - $data['default'] = ($langcode == $default->id); - $data['name'] = $data['label']; - $this->languages[$langcode] = new Language($data); - $weight = max(array($weight, $this->languages[$langcode]->weight)); - } + // Prepopulate the language list with the default language to keep things + // working even if we have no configuration. + $default = $this->getDefaultLanguage(); + $this->languages = array($default->id => $default); - // Add locked languages, they will be filtered later if needed. - $this->languages += $this->getDefaultLockedLanguages($weight); + // Retrieve the list of languages defined in configuration. + $prefix = 'language.entity.'; + $config_ids = $this->configFactory->listAll($prefix); - // Sort the language list by weight then title. - Language::sort($this->languages); + // Instantiate languages from config objects. + $weight = 0; + foreach ($this->configFactory->loadMultiple($config_ids) as $config) { + $data = $config->get(); + $langcode = $data['id']; + // Initialize default property so callers have an easy reference and can + // save the same object without data loss. + $data['default'] = ($langcode == $default->id); + $data['name'] = $data['label']; + $this->languages[$langcode] = new Language($data); + $weight = max(array($weight, $this->languages[$langcode]->weight)); } + // Add locked languages, they will be filtered later if needed. + $this->languages += $this->getDefaultLockedLanguages($weight); + + // Sort the language list by weight then title. + Language::sort($this->languages); + return parent::getLanguages($flags); } diff --git a/core/modules/language/src/Tests/LanguageSelectorTranslatableTest.php b/core/modules/language/src/Tests/LanguageSelectorTranslatableTest.php new file mode 100644 index 0000000..23d3756 --- /dev/null +++ b/core/modules/language/src/Tests/LanguageSelectorTranslatableTest.php @@ -0,0 +1,80 @@ +administrator = $this->drupalCreateUser($this->getAdministratorPermissions(), 'administrator'); + $this->drupalLogin($this->administrator); + + } + /** + * Returns an array of permissions needed for the translator. + */ + protected function getAdministratorPermissions() { + return array_filter( + array('translate interface', + 'administer content translation', + 'create content translations', + 'update content translations', + 'delete content translations', + 'administer languages' + ) + ); + } + + /** + * Test Content Translation language selectors are correctly translate. + */ + public function testLanguageStringSelector() { + // Add another language. + $edit = array('predefined_langcode' => 'es'); + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + + // Translate the string English in Spanish (Inglés). Override config entity. + $name_translation = 'Inglés'; + $override = \Drupal::languageManager()->getLanguageConfigOverride('es', 'language.entity.en')->set('label', $name_translation)->save(); + + // Check label is set correctly. + $this->assertEqual($override->get('label'), $name_translation, 'Language label for English is translated into Spanish.'); + + // Check content translation overview selector. + $path = 'es/admin/config/regional/content-language'; + $this->drupalGet($path); + + // Get en language from selector. + $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => 'edit-settings-node-node-settings-language-langcode', ':option' => 'en')); + + // Check the language text is translated. + $this->assertEqual((string) $elements[0], $name_translation, 'Checking the option string English is translated to Spanish.'); + } +}