diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index c15107c609b80d7de7cb0e77a5c84210f5bc82d3..6c51880476bc34012ec06ddeba42e92570945e86 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1493,6 +1493,11 @@ function install_import_translations(&$install_state) { language_save($language); } + // If a non-english language was selected, remove English. + if ($langcode != 'en') { + language_delete('en'); + } + // Collect files to import for this language. $batch = locale_translate_batch_import_files(array('langcode' => $langcode)); if (!empty($batch)) { diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index b388986769a628821f7eeba1a537713610274b36..78a95a9d9845bfd1f37a95f53361659fbb51d129 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -693,9 +693,10 @@ function language_negotiation_configure_url_form($form, &$form_state) { $prefixes = language_negotiation_url_prefixes(); $domains = language_negotiation_url_domains(); foreach ($languages as $langcode => $language) { + $t_args = array('%language' => $language->name, '%langcode' => $language->langcode); $form['prefix'][$langcode] = array( '#type' => 'textfield', - '#title' => t('%language (%langcode) path prefix', array('%language' => $language->name, '%langcode' => $language->langcode)), + '#title' => $language->default ? t('%language (%langcode) path prefix (Default language)', $t_args) : t('%language (%langcode) path prefix', $t_args), '#maxlength' => 64, '#default_value' => isset($prefixes[$langcode]) ? $prefixes[$langcode] : '', '#field_prefix' => $base_url . '/', @@ -739,6 +740,11 @@ function language_negotiation_configure_url_form_validate($form, &$form_state) { form_error($form['prefix'][$langcode], t('The prefix may only be left blank for the default language.')); } } + elseif (strpos($value, '/') !== FALSE) { + // Throw a form error if the string contains a slash, + // which would not work. + form_error($form['prefix'][$langcode], t('The prefix may not contain a slash.')); + } elseif (isset($count[$value]) && $count[$value] > 1) { // Throw a form error if there are two languages with the same // domain/prefix. diff --git a/core/modules/language/language.module b/core/modules/language/language.module index e911980097885e687df16964b413f2ddfc1bb045..67c0d6fb9e2bcf8891bc3daafd37e642006214e0 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -236,6 +236,10 @@ function language_save($language) { // Kill the static cache in language_list(). drupal_static_reset('language_list'); + // Update URL Prefixes for all languages after the new default language is + // propagated and the language_list() cache is flushed. + language_negotiation_url_prefixes_update(); + return $language; } @@ -457,40 +461,12 @@ function language_language_insert($language) { language_negotiation_include(); - // Add new language to the list of language prefixes. - $prefixes = language_negotiation_url_prefixes(); - $prefixes[$language->langcode] = (empty($language->default) ? $language->langcode : ''); - language_negotiation_url_prefixes_save($prefixes); - // Add language to the list of language domains. $domains = language_negotiation_url_domains(); $domains[$language->langcode] = ''; language_negotiation_url_domains_save($domains); } -/** - * Implements hook_language_update(). - */ -function language_language_update($language) { - if (!empty($language->locked)) { - return; - } - - language_negotiation_include(); - - // If the language is the default, then ensure that no other languages have - // blank prefix codes. - if (!empty($language->default)) { - $prefixes = language_negotiation_url_prefixes(); - foreach ($prefixes as $langcode => $prefix) { - if ($prefix == '' && $langcode != $language->langcode) { - $prefixes[$langcode] = $langcode; - } - } - language_negotiation_url_prefixes_save($prefixes); - } -} - /** * Implements hook_language_delete(). */ diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index 549e80ab18d49342b1968ecdb762838dc9598989..837cbd27a79a1b4d90c2fec0c2e87e3598f3f048 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -473,6 +473,24 @@ function language_negotiation_url_prefixes() { return variable_get('language_negotiation_url_prefixes', array()); } +/** + * Update the list of prefixes from the installed languages. + */ +function language_negotiation_url_prefixes_update() { + $prefixes = language_negotiation_url_prefixes(); + foreach (language_list() as $language) { + // The prefix for this language should be updated if it's not assigned yet + // or the prefix is set to the empty string. + if (empty($prefixes[$language->langcode])) { + // For the default language, set the prefix to the empty string, + // otherwise use the langcode. + $prefixes[$language->langcode] = !empty($language->default) ? '' : $language->langcode; + } + // Otherwise we keep the configured prefix. + } + language_negotiation_url_prefixes_save($prefixes); +} + /** * Saves language prefix settings. */ diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php index 0372e1bd57719a40dc3f353fe49a0c765120311e..76af7307efdf1d6fd533ac092e4ffd776e1cd2fd 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php @@ -41,40 +41,62 @@ function testLanguageConfiguration() { // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', t('Default English has no path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); // Add predefined language. $edit = array( 'predefined_langcode' => 'fr', ); - $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + $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)), t('Correct page redirection.')); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', t('Default English has no path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); // Check if French has a path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', t('French has a path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.'); // Check if we can change the default language. $this->drupalGet('admin/config/regional/language'); - $this->assertFieldChecked('edit-site-default-en', t('English is the default language.')); + $this->assertFieldChecked('edit-site-default-en', 'English is the default language.'); // Change the default language. $edit = array( 'site_default' => 'fr', ); $this->drupalPost(NULL, $edit, t('Save configuration')); - $this->assertNoFieldChecked('edit-site-default-en', t('Default language updated.')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.')); + $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.'); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Check if a valid language prefix is added afrer changing the default // language. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', t('A valid path prefix has been added to the previous default language.')); + $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.'); // Check if French still has a path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', t('French still has a path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.'); + + // Check that prefix can be changed. + $edit = array( + 'prefix[fr]' => 'french', + ); + $this->drupalPost(NULL, $edit, t('Save configuration')); + $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.'); + + // Check that prefix of non default langauge cannot be changed to + // empty string. + $edit = array( + 'prefix[en]' => '', + ); + $this->drupalPost(NULL, $edit, t('Save configuration')); + $this->assertText(t('The prefix may only be left blank for the default language.'), 'English prefix cannot be changed to empty string.'); + + // Check that prefix cannot be changed to contain a slash. + $edit = array( + 'prefix[en]' => 'foo/bar', + ); + $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.'); } }