From 045cc0e43f681fa66d1915941d34611e6abf5199 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sat, 8 Feb 2025 19:04:31 +0000 Subject: [PATCH] =?UTF-8?q?Issue=20#2927338=20by=20berdir,=20anmolgoyal74,?= =?UTF-8?q?=20swatichouhan012,=20smustgrave,=20alexpott,=20g=C3=A1bor=20ho?= =?UTF-8?q?jtsy:=20Ensure=20config=20entity=20langcode=20property=20does?= =?UTF-8?q?=20not=20change=20when=20installing,=20adding=20or=20editing=20?= =?UTF-8?q?a=20language?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 9e7842eb89ce1c57d6418922ca8d3b806e463fb5) --- core/includes/install.core.inc | 7 +++++++ .../language/src/Form/LanguageAddForm.php | 6 +++++- .../language/src/Form/LanguageFormBase.php | 4 ---- core/modules/locale/src/Hook/LocaleHooks.php | 4 +++- ...istributionProfileTranslationQueryTest.php | 3 ++- .../DistributionProfileTranslationTest.php | 3 ++- .../InstallerTranslationQueryTest.php | 3 ++- .../Installer/InstallerTranslationTest.php | 20 ++++++++++++++++++- 8 files changed, 40 insertions(+), 10 deletions(-) diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index ee1cacdded53..81d339f27936 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1691,6 +1691,13 @@ function install_download_additional_translations_operations(&$install_state) { if (!($language = ConfigurableLanguage::load($langcode))) { // Create the language if not already shipped with a profile. $language = ConfigurableLanguage::createFromLangcode($langcode); + + $standard_languages = LanguageManager::getStandardLanguageList(); + if (isset($standard_languages[$langcode])) { + // Use the localized language label since the site is being installed + // with that language. + $language->setName($standard_languages[$langcode][1]); + } } $language->save(); diff --git a/core/modules/language/src/Form/LanguageAddForm.php b/core/modules/language/src/Form/LanguageAddForm.php index 44900447060b..9640e0b8fcee 100644 --- a/core/modules/language/src/Form/LanguageAddForm.php +++ b/core/modules/language/src/Form/LanguageAddForm.php @@ -152,7 +152,11 @@ class LanguageAddForm extends LanguageFormBase { } else { $standard_languages = LanguageManager::getStandardLanguageList(); - $label = $standard_languages[$langcode][0]; + // Translate the label to the current language, this is consistent with + // the label in the form select, see + // \Drupal\language\ConfigurableLanguageManager::getStandardLanguageListWithoutConfigured(). + // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString + $label = $this->t($standard_languages[$langcode][0]); $direction = $standard_languages[$langcode][2] ?? ConfigurableLanguage::DIRECTION_LTR; } $entity->set('id', $langcode); diff --git a/core/modules/language/src/Form/LanguageFormBase.php b/core/modules/language/src/Form/LanguageFormBase.php index edea6a003838..76806b594169 100644 --- a/core/modules/language/src/Form/LanguageFormBase.php +++ b/core/modules/language/src/Form/LanguageFormBase.php @@ -52,10 +52,6 @@ abstract class LanguageFormBase extends EntityForm { '#title' => $this->t('Language code'), '#markup' => $language->id(), ]; - $form['langcode'] = [ - '#type' => 'value', - '#value' => $language->id(), - ]; } else { $form['langcode'] = [ diff --git a/core/modules/locale/src/Hook/LocaleHooks.php b/core/modules/locale/src/Hook/LocaleHooks.php index e0afe107c87c..03eca5333618 100644 --- a/core/modules/locale/src/Hook/LocaleHooks.php +++ b/core/modules/locale/src/Hook/LocaleHooks.php @@ -316,7 +316,9 @@ class LocaleHooks { */ #[Hook('form_language_admin_edit_form_alter')] public function formLanguageAdminEditFormAlter(&$form, FormStateInterface $form_state) : void { - if ($form['langcode']['#type'] == 'value' && $form['langcode']['#value'] == 'en') { + /** @var \Drupal\language\ConfigurableLanguageInterface $language */ + $language = $form_state->getFormObject()->getEntity(); + if ($language->id() == 'en') { $form['locale_translate_english'] = [ '#title' => t('Enable interface translation to English'), '#type' => 'checkbox', diff --git a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php index 8de136ee79b0..764e9d15d65d 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php @@ -120,7 +120,8 @@ class DistributionProfileTranslationQueryTest extends InstallerTestBase { // Verify German was configured but not English. $this->drupalGet('admin/config/regional/language'); - $this->assertSession()->pageTextContains('German'); + // cspell:ignore deutsch + $this->assertSession()->pageTextContains('Deutsch'); $this->assertSession()->pageTextNotContains('English'); } diff --git a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php index b955773ba066..75db313b14b8 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php @@ -110,7 +110,8 @@ class DistributionProfileTranslationTest extends InstallerTestBase { // Verify German was configured but not English. $this->drupalGet('admin/config/regional/language'); - $this->assertSession()->pageTextContains('German'); + // cspell:ignore deutsch + $this->assertSession()->pageTextContains('Deutsch'); $this->assertSession()->pageTextNotContains('English'); } diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationQueryTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationQueryTest.php index 5cacdc594b9a..532c23a814ee 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationQueryTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationQueryTest.php @@ -63,7 +63,8 @@ class InstallerTranslationQueryTest extends InstallerTestBase { // Verify German was configured but not English. $this->drupalGet('admin/config/regional/language'); - $this->assertSession()->pageTextContains('German'); + // cspell:ignore deutsch + $this->assertSession()->pageTextContains('Deutsch'); $this->assertSession()->pageTextNotContains('English'); } diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php index c0313aab7e6e..df41e7bf510e 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Drupal\FunctionalTests\Installer; use Drupal\Core\Database\Database; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\user\Entity\User; /** @@ -86,7 +87,8 @@ class InstallerTranslationTest extends InstallerTestBase { // Verify German was configured but not English. $this->drupalGet('admin/config/regional/language'); - $this->assertSession()->pageTextContains('German'); + // cspell:ignore deutsch + $this->assertSession()->pageTextContains('Deutsch'); $this->assertSession()->pageTextNotContains('English'); // The current container still has the english as current language, rebuild. @@ -142,7 +144,20 @@ class InstallerTranslationTest extends InstallerTestBase { $this->submitForm($edit, 'Add language'); $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings'); $this->assertFalse($override_en->isNew()); + $this->assertSession()->pageTextContains('English de'); $this->assertEquals('Anonymous', $override_en->get('anonymous')); + + $english = ConfigurableLanguage::load('en'); + $this->assertEquals('de', $english->language()->getId(), 'The langcode of the english language is de.'); + + // English is guaranteed to be the second language, click the second + // language edit link. + $this->clickLink('Edit', 1); + $this->assertSession()->fieldValueEquals('label', 'English de'); + $this->submitForm([], 'Save language'); + + $english = ConfigurableLanguage::load('en'); + $this->assertEquals('de', $english->language()->getId(), 'The langcode of the english language is de.'); } /** @@ -165,6 +180,9 @@ msgstr "Save and continue $langcode" msgid "Anonymous" msgstr "Anonymous $langcode" +msgid "English" +msgstr "English $langcode" + msgid "Resolve all issues below to continue the installation. For help configuring your database server, see the installation handbook, or contact your hosting provider." msgstr "Beheben Sie alle Probleme unten, um die Installation fortzusetzen. Informationen zur Konfiguration der Datenbankserver finden Sie in der Installationshandbuch, oder kontaktieren Sie Ihren Hosting-Anbieter."