summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-11-06 09:41:24 (GMT)
committerAlex Pott2014-11-06 09:41:24 (GMT)
commit2095c89ff3e4dd4cbebe5e22b70d7ab61215814f (patch)
tree500c6f93772ce9d4bcd4fefda3faa4d6715914e3
parent1a222d4de893284e06ebbaf4d9ca40c3c4160b5c (diff)
Issue #365615 followup by attiks, YesCT, Gábor Hojtsy, mgifford, Albert Volkman, plach, webwarrior, David_Rothstein, penyaskito, smokris | yang_yi_cn: Fixed Followups: Language detection not working correctly for most Chinese readers (and add a user interface for all browser language mappings).
-rw-r--r--core/modules/language/language.admin.inc8
-rw-r--r--core/modules/language/language.module2
-rw-r--r--core/modules/language/src/Form/NegotiationBrowserDeleteForm.php8
-rw-r--r--core/modules/language/src/Form/NegotiationBrowserForm.php14
-rw-r--r--core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php12
5 files changed, 29 insertions, 15 deletions
diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc
index d7a0415..ebae05c 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 68126f6..6901c91 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 = '<p>' . t('Browsers use different language codes to refer to the same languages. You can add and edit mappings from browser language codes to the <a href="!configure-languages">languages used</a>.', array('!configure-languages' => \Drupal::url('language.admin_overview'))) . '</p>';
+ $output = '<p>' . 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 <a href="!configure-languages">site languages</a>.', array('!configure-languages' => \Drupal::url('language.admin_overview'))) . '</p>';
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 0c0a447..aa8fbea 100644
--- a/core/modules/language/src/Form/NegotiationBrowserDeleteForm.php
+++ b/core/modules/language/src/Form/NegotiationBrowserDeleteForm.php
@@ -65,6 +65,14 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
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 aea7ad1..8cbac11 100644
--- a/core/modules/language/src/Form/NegotiationBrowserForm.php
+++ b/core/modules/language/src/Form/NegotiationBrowserForm.php
@@ -89,12 +89,16 @@ class NegotiationBrowserForm extends ConfigFormBase {
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 @@ class NegotiationBrowserForm extends ConfigFormBase {
'#type' => 'textfield',
'#title' => $this->t('Browser language code'),
'#description' => $this->t('Use language codes as <a href="@w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', 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 @@ class NegotiationBrowserForm extends ConfigFormBase {
$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 @@ class NegotiationBrowserForm extends ConfigFormBase {
$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 62ee8e3..f724338 100644
--- a/core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php
+++ b/core/modules/language/src/Tests/LanguageBrowserDetectionUnitTest.php
@@ -186,6 +186,14 @@ class LanguageBrowserDetectionUnitTest extends WebTestBase {
$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 @@ class LanguageBrowserDetectionUnitTest extends WebTestBase {
'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 @@ class LanguageBrowserDetectionUnitTest extends WebTestBase {
'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.');
}