diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index d7a041514c237e8479a9ad68c338ef0d3d095ea4..ebae05c684ce037411bfd77a9af3732964302734 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -115,9 +115,6 @@ function theme_language_negotiation_configure_browser_form_table($variables) { $links['delete'] = array( 'title' => t('Delete'), 'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $key]), - 'attributes' => array( - 'class' => array('image-style-link'), - ), ); $row[] = array( 'data' => array( @@ -131,7 +128,7 @@ function theme_language_negotiation_configure_browser_form_table($variables) { $header = array( t('Browser language code'), - t('Drupal language'), + t('Site language'), t('Operations'), ); @@ -139,7 +136,8 @@ function theme_language_negotiation_configure_browser_form_table($variables) { '#type' => 'table', '#header' => $header, '#rows' => $rows, - '#attributes' => array('id' => 'lang-neg-browser'), + '#empty' => t('No browser language mappings available.'), + '#attributes' => array('id' => 'language-negotiation-browser'), ); $output = drupal_render($table); diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 68126f6ce137444bc56c995dcb8ea39254cb74f7..6901c91c579cd3d65503aafa270e0688700514ae 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -63,7 +63,7 @@ function language_help($route_name, RouteMatchInterface $route_match) { return $output; case 'language.negotiation_browser': - $output = '

' . t('Browsers use different language codes to refer to the same languages. You can add and edit mappings from browser language codes to the languages used.', array('!configure-languages' => \Drupal::url('language.admin_overview'))) . '

'; + $output = '

' . t('Browsers use different language codes to refer to the same languages. Internally, a best effort is made to determine the correct language based on the code that the browser sends. You can add and edit additional mappings from browser language codes to site languages.', array('!configure-languages' => \Drupal::url('language.admin_overview'))) . '

'; return $output; case 'language.negotiation_selected': diff --git a/core/modules/language/src/Form/NegotiationBrowserDeleteForm.php b/core/modules/language/src/Form/NegotiationBrowserDeleteForm.php index 0c0a4474f18161e7eb066ffb16d8c407d7129646..aa8fbeade009e782ec5b4da4713e5703d92896c3 100644 --- a/core/modules/language/src/Form/NegotiationBrowserDeleteForm.php +++ b/core/modules/language/src/Form/NegotiationBrowserDeleteForm.php @@ -65,6 +65,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) { if (array_key_exists($this->browserLangcode, $mappings)) { unset($mappings[$this->browserLangcode]); language_set_browser_drupal_langcode_mappings($mappings); + + $args = array( + '%browser' => $this->browserLangcode, + ); + + $this->logger('language')->notice('The browser language detection mapping for the %browser browser language code has been deleted.', $args); + + drupal_set_message($this->t('The mapping for the %browser browser language code has been deleted.', $args)); } $form_state->setRedirect('language.negotiation_browser'); diff --git a/core/modules/language/src/Form/NegotiationBrowserForm.php b/core/modules/language/src/Form/NegotiationBrowserForm.php index aea7ad19d9f03e853e0db7cc0fda1b6d13ba7ea8..8cbac111e8e7e0dbfe0354357b9506cc1b9f1208 100644 --- a/core/modules/language/src/Form/NegotiationBrowserForm.php +++ b/core/modules/language/src/Form/NegotiationBrowserForm.php @@ -89,12 +89,16 @@ public function buildForm(array $form, FormStateInterface $form_state) { foreach ($mappings as $browser_langcode => $drupal_langcode) { $form['mappings'][$browser_langcode] = array( 'browser_langcode' => array( + '#title' => $this->t('Browser language code'), + '#title_display' => 'invisible', '#type' => 'textfield', '#default_value' => $browser_langcode, '#size' => 20, '#required' => TRUE, ), 'drupal_langcode' => array( + '#title' => $this->t('Site language'), + '#title_display' => 'invisible', '#type' => 'select', '#options' => $language_options, '#default_value' => $drupal_langcode, @@ -113,14 +117,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => $this->t('Browser language code'), '#description' => $this->t('Use language codes as defined by the W3C for interoperability. Examples: "en", "en-gb" and "zh-hant".', array('@w3ctags' => 'http://www.w3.org/International/articles/language-tags/')), - '#default_value' => '', '#size' => 20, ); $form['new_mapping']['drupal_langcode'] = array( '#type' => 'select', - '#title' => $this->t('Drupal language'), + '#title' => $this->t('Site language'), '#options' => $language_options, - '#default_value' => '', ); return parent::buildForm($form, $form_state); @@ -134,16 +136,15 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $unique_values = array(); // Check all mappings. - $mappings = array(); if ($form_state->hasValue('mappings')) { $mappings = $form_state->getValue('mappings'); foreach ($mappings as $key => $data) { // Make sure browser_langcode is unique. if (array_key_exists($data['browser_langcode'], $unique_values)) { - $form_state->setErrorByName('mappings][' . $key . '][browser_langcode', $this->t('Browser language codes must be unique.')); + $form_state->setErrorByName('mappings][new_mapping][browser_langcode', $this->t('Browser language codes must be unique.')); } elseif (preg_match('/[^a-z\-]/', $data['browser_langcode'])) { - $form_state->setErrorByName('mappings][' . $key . '][browser_langcode', $this->t('Browser language codes can only contain lowercase letters and a hyphen(-).')); + $form_state->setErrorByName('mappings][new_mapping][browser_langcode', $this->t('Browser language codes can only contain lowercase letters and a hyphen(-).')); } $unique_values[$data['browser_langcode']] = $data['drupal_langcode']; } @@ -175,7 +176,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $config->setData($mappings); $config->save(); } - $form_state->setRedirect('language.negotiation'); parent::submitForm($form, $form_state); } diff --git a/core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php b/core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php index 62ee8e30b9c2ad408458b7580ded62a9d74e8033..f724338edd332a8e40331887e08f12f63fee0a36 100644 --- a/core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php +++ b/core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php @@ -186,6 +186,14 @@ function testUIBrowserLanguageMappings() { $edit = array(); $this->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm')); + // We need raw here because %browser will add HTML. + $t_args = array( + '%browser' => $browser_langcode, + ); + $this->assertRaw(t('The mapping for the %browser browser language code has been deleted.', $t_args), 'The test browser language code has been deleted.'); + + // Check we went back to the browser negotiation mapping overview. + $this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE])); // Check that ch-zn no longer exists. $this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.'); @@ -195,7 +203,7 @@ function testUIBrowserLanguageMappings() { 'new_mapping[drupal_langcode]' => 'en', ); $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); - $this->drupalGet('admin/config/regional/language/detection/browser'); + $this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE])); $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); $this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.'); @@ -217,7 +225,7 @@ function testUIBrowserLanguageMappings() { 'mappings[xx][drupal_langcode]' => 'zh-hans', ); $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); - $this->drupalGet('admin/config/regional/language/detection/browser'); + $this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE])); $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); $this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.'); }