Commit 3c2b78d7 authored by Dries's avatar Dries

- Patch #1468930 by dawehner, Gábor Hojtsy, plach, das-peter, fubhy: clean up...

- Patch  #1468930 by dawehner, Gábor Hojtsy, plach, das-peter, fubhy: clean up and move the code for the negotiation functionality from locale module to language module.
parent 1fd81149
......@@ -1324,7 +1324,7 @@ function install_select_language(&$install_state) {
*/
function install_select_language_form($form, &$form_state, $files) {
include_once DRUPAL_ROOT . '/core/includes/standard.inc';
include_once DRUPAL_ROOT . '/core/includes/locale.inc';
include_once DRUPAL_ROOT . '/core/modules/language/language.negotiation.inc';
$standard_languages = standard_language_list();
$select_options = array();
......@@ -1345,7 +1345,7 @@ function install_select_language_form($form, &$form_state, $files) {
);
}
$browser_langcode = locale_language_from_browser($languages);
$browser_langcode = language_from_browser($languages);
$form['langcode'] = array(
'#type' => 'select',
'#options' => $select_options,
......@@ -1477,7 +1477,6 @@ function install_profile_modules(&$install_state) {
* The batch definition, if there are language files to import.
*/
function install_import_translations(&$install_state) {
include_once DRUPAL_ROOT . '/core/includes/locale.inc';
include_once drupal_get_path('module', 'locale') . '/locale.bulk.inc';
$langcode = $install_state['parameters']['langcode'];
......@@ -1773,8 +1772,6 @@ function install_check_requirements($install_state) {
* Forms API array definition for site configuration.
*/
function _install_configure_form($form, &$form_state, &$install_state) {
include_once DRUPAL_ROOT . '/core/includes/locale.inc';
$form['site_information'] = array(
'#type' => 'fieldset',
'#title' => st('Site information'),
......
......@@ -397,7 +397,7 @@ function language_url_split_prefix($path, $languages) {
$prefix = array_shift($args);
// Search prefix within enabled languages.
$prefixes = locale_language_negotiation_url_prefixes();
$prefixes = language_negotiation_url_prefixes();
foreach ($languages as $language) {
if (isset($prefixes[$language->langcode]) && $prefixes[$language->langcode] == $prefix) {
// Rebuild $path with the language removed.
......
This diff is collapsed.
......@@ -144,7 +144,7 @@ function update_prepare_stored_includes() {
$negotiation = variable_get("language_negotiation_$language_type", array());
foreach ($negotiation as $method_id => &$method) {
if (isset($method['file']) && $method['file'] == 'includes/locale.inc') {
$method['file'] = 'core/includes/locale.inc';
$method['file'] = 'core/modules/language/language.negotiation.inc';
}
}
variable_set("language_negotiation_$language_type", $negotiation);
......
......@@ -2708,7 +2708,6 @@ class FieldTranslationsTestCase extends FieldTestCase {
field_create_instance($instance);
$this->instance = field_read_instance('test_entity', $this->field_name, 'test_bundle');
require_once DRUPAL_ROOT . '/core/includes/locale.inc';
for ($i = 0; $i < 3; ++$i) {
$language = (object) array(
'langcode' => 'l' . $i,
......
This diff is collapsed.
name = Language
description = Lets you configure a number of languages to be used on your website.
description = Lets you configure a number of languages to be used on your website and provides language negotiation functionality.
package = Core
version = VERSION
core = 8.x
......
......@@ -7,10 +7,19 @@
/**
* Implements hook_install().
*
* Enable URL language negotiation by default in order to have a basic working
* system on multilingual sites without needing any preliminary configuration.
*/
function language_install() {
// Add the default language to the database too.
language_save(language_default());
// Enable URL language detection for each configurable language type.
require_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach (language_types_get_configurable(FALSE) as $type) {
language_negotiation_set($type, array(LANGUAGE_NEGOTIATION_URL => 0));
}
}
/**
......@@ -21,6 +30,20 @@ function language_uninstall() {
variable_del('language_default');
variable_del('language_count');
// Clear variables.
variable_del('language_types');
variable_del('language_negotiation_url_part');
variable_del('language_negotiation_url_prefixes');
variable_del('language_negotiation_url_domains');
variable_del('language_negotiation_session_param');
variable_del('language_content_type_default');
variable_del('language_content_type_negotiation');
foreach (language_types_get_all() as $type) {
variable_del("language_negotiation_$type");
variable_del("language_negotiation_methods_weight_$type");
}
// Re-initialize the language system so successive calls to t() and other
// functions will not expect languages to be present.
drupal_language_initialize();
......
This diff is collapsed.
......@@ -78,7 +78,7 @@ class LanguageListTest extends DrupalWebTestCase {
$edit = array(
'languages[en][enabled]' => FALSE,
);
$this->drupalPost($path, $edit, t('Save configuration'));
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertNoFieldChecked('edit-languages-en-enabled', t('Language disabled.'));
// Set disabled language to be the default and ensure it is re-enabled.
......
This diff is collapsed.
.locale-untranslated {
font-style: normal;
text-decoration: line-through;
......@@ -24,9 +23,3 @@
float: left; /* LTR */
padding: 3ex 0 0 1em; /* LTR */
}
.language-switcher-locale-session a.active {
color: #0062a0;
}
.language-switcher-locale-session a.session-active {
color: #000000;
}
name = Locale
description = Provides language negotiation functionality and user interface translation to languages other than English.
description = Provides user interface translation to languages other than English.
package = Core
version = VERSION
core = 8.x
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -639,10 +639,14 @@ function overlay_overlay_parent_initialize() {
}
drupal_add_js(array('overlay' => array('paths' => $paths)), 'setting');
$path_prefixes = array();
if (module_exists('locale') && variable_get('locale_language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX) == LANGUAGE_NEGOTIATION_URL_PREFIX) {
// Skip the empty string indicating the default language. We always accept
// paths without a prefix.
$path_prefixes = array_values(array_filter(locale_language_negotiation_url_prefixes()));
if (module_exists('language')) {
language_negotiation_include();
if (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX) == LANGUAGE_NEGOTIATION_URL_PREFIX) {
// Skip the empty string indicating the default language. We always accept
// paths without a prefix.
$path_prefixes = language_negotiation_url_prefixes();
$path_prefixes = array_values(array_filter($path_prefixes));
}
}
drupal_add_js(array('overlay' => array('pathPrefixes' => $path_prefixes)), 'setting');
// Pass along the Ajax callback for rerendering sections of the parent window.
......
......@@ -311,7 +311,7 @@ class PathLanguageTestCase extends PathTestCase {
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
// Enable URL language detection and selection.
$edit = array('language_interface[enabled][locale-url]' => 1);
$edit = array('language_interface[enabled][language-url]' => 1);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
}
......@@ -360,8 +360,8 @@ class PathLanguageTestCase extends PathTestCase {
// Confirm that the alias is returned by url(). Languages are cached on
// many levels, and we need to clear those caches.
drupal_static_reset('language_list');
drupal_static_reset('locale_url_outbound_alter');
drupal_static_reset('locale_language_url_rewrite_url');
drupal_static_reset('language_url_outbound_alter');
drupal_static_reset('language_url_rewrite_url');
$languages = language_list();
$url = url('node/' . $french_node->nid, array('language' => $languages[$french_node->langcode]));
$this->assertTrue(strpos($url, $edit['path[alias]']), t('URL contains the path alias.'));
......@@ -369,10 +369,10 @@ class PathLanguageTestCase extends PathTestCase {
// Confirm that the alias works even when changing language negotiation
// options. Enable User language detection and selection over URL one.
$edit = array(
'language_interface[enabled][locale-user]' => 1,
'language_interface[weight][locale-user]' => -9,
'language_interface[enabled][locale-url]' => 1,
'language_interface[weight][locale-url]' => -8,
'language_interface[enabled][language-user]' => 1,
'language_interface[weight][language-user]' => -9,
'language_interface[enabled][language-url]' => 1,
'language_interface[weight][language-url]' => -8,
);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
......@@ -396,7 +396,7 @@ class PathLanguageTestCase extends PathTestCase {
$this->assertText($french_node->title, 'Alias for French translation works.');
// Disable URL language negotiation.
$edit = array('language_interface[enabled][locale-url]' => FALSE);
$edit = array('language_interface[enabled][language-url]' => FALSE);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
// Check that the English alias still works.
......@@ -454,7 +454,7 @@ class PathLanguageUITestCase extends PathTestCase {
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
// Enable URL language detection and selection.
$edit = array('language_interface[enabled][locale-url]' => 1);
$edit = array('language_interface[enabled][language-url]' => 1);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
}
......@@ -541,7 +541,7 @@ class PathMonolingualTestCase extends PathTestCase {
$this->assertEqual(language_default()->langcode, 'fr', t('French is the default language'));
// Set language detection to URL.
$edit = array('language_interface[enabled][locale-url]' => TRUE);
$edit = array('language_interface[enabled][language-url]' => TRUE);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
// Force languages to be initialized.
......
......@@ -55,7 +55,7 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
// Ensure that the language switcher has been correctly upgraded. We need to
// assert the expected HTML id because the block might appear even if the
// language negotiation settings are not properly upgraded.
$this->assertTrue($this->xpath('//div[@id="block-locale-language-interface"]'), t('The language switcher block is being correctly showed.'));
$this->assertTrue($this->xpath('//div[@id="block-language-language-interface"]'), t('The language switcher block is being correctly showed.'));
// Test that the 'language' property was properly renamed to 'langcode'.
$language_none_nid = 38;
......@@ -99,10 +99,16 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
// Check if language negotiation weights were renamed properly. This is a
// reproduction of the previous weights from the dump.
$expected_weights = array('locale-url' => '-8', 'locale-session' => '-6', 'locale-user' => '-4', 'locale-browser' => '-2', 'language-default' => '10');
$expected_weights = array(
'language-url' => '-8',
'language-session' => '-6',
'language-user' => '-4',
'language-browser' => '-2',
'language-default' => '10',
);
// Check that locale_language_providers_weight_language is correctly
// renamed.
$current_weights = variable_get('locale_language_negotiation_methods_weight_language_interface', array());
$current_weights = variable_get('language_negotiation_methods_weight_language_interface', array());
$this->assertTrue(serialize($expected_weights) == serialize($current_weights), t('Language negotiation method weights upgraded.'));
// Look up migrated plural string.
......@@ -133,7 +139,8 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
$domains = locale_language_negotiation_url_domains();
language_negotiation_include();
$domains = language_negotiation_url_domains();
$this->assertTrue($domains['ca'] == $language_domain, t('Language domain for Catalan properly upgraded.'));
}
......
......@@ -1899,7 +1899,6 @@ function system_rss_feeds_settings() {
* @see system_regional_settings_submit()
*/
function system_regional_settings() {
include_once DRUPAL_ROOT . '/core/includes/locale.inc';
$countries = country_get_list();
// Date settings:
......
......@@ -4035,3 +4035,17 @@ function system_admin_paths() {
);
return $paths;
}
/**
* Get list of all predefined and custom countries.
*
* @return
* An array of all country code => country name pairs.
*/
function country_get_list() {
include_once DRUPAL_ROOT . '/core/includes/standard.inc';
$countries = standard_country_list();
// Allow other modules to modify the country list.
drupal_alter('countries', $countries);
return $countries;
}
......@@ -49,7 +49,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Enable the language switcher block.
$language_type = LANGUAGE_TYPE_INTERFACE;
$edit = array("blocks[locale_$language_type][region]" => 'sidebar_first');
$edit = array("blocks[language_$language_type][region]" => 'sidebar_first');
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
// Reset static caches in our local language environment.
......@@ -76,7 +76,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Check that the "add translation" link uses a localized path.
$languages = language_list();
$prefixes = locale_language_negotiation_url_prefixes();
$prefixes = language_negotiation_url_prefixes();
$this->drupalGet('node/' . $node->nid . '/translate');
$this->assertLinkByHref($prefixes['es'] . '/node/add/' . str_replace('_', '-', $node->type), 0, t('The "add translation" link for %language points to the localized path of the target language.', array('%language' => $languages['es']->name)));
......@@ -169,7 +169,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Check that links to the displayed translation appear only in the language
// switcher block.
$this->assertLanguageSwitchLinks($node, $node, FALSE, 'node');
$this->assertLanguageSwitchLinks($node, $node, TRUE, 'block-locale');
$this->assertLanguageSwitchLinks($node, $node, TRUE, 'block-language');
// Unpublish the Spanish translation to check that the related language
// switch link is not shown.
......@@ -182,7 +182,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Check that content translation links are shown even when no language
// negotiation is configured.
$this->drupalLogin($this->admin_user);
$edit = array('language_interface[enabled][locale-url]' => FALSE);
$edit = array('language_interface[enabled][language-url]' => FALSE);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
$this->resetCaches();
$edit = array('status' => TRUE);
......@@ -203,7 +203,7 @@ class TranslationTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->translator);
// Create a Basic page in English.
$type = 'block-locale';
$type = 'block-language';
$node = $this->createPage($this->randomName(), $this->randomName(), 'en');
$this->assertLanguageSwitchLinks($node, $node, TRUE, $type);
$this->assertLanguageSwitchLinks($node, $this->emptyNode('es'), TRUE, $type);
......@@ -259,8 +259,8 @@ class TranslationTestCase extends DrupalWebTestCase {
*/
function resetCaches() {
drupal_static_reset('language_list');
drupal_static_reset('locale_url_outbound_alter');
drupal_static_reset('locale_language_url_rewrite_url');
drupal_static_reset('language_url_outbound_alter');
drupal_static_reset('language_url_rewrite_url');
}
/**
......@@ -422,7 +422,7 @@ class TranslationTestCase extends DrupalWebTestCase {
*/
function assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = NULL) {
if (empty($types)) {
$types = array('node', 'block-locale');
$types = array('node', 'block-language');
}
elseif (is_string($types)) {
$types = array($types);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment