- Patch #1280538 by fastangel, Gábor Hojtsy, plach: Language negotiation UX: default the path prefix setting on installation so that it actually works right away.
parent
89d83c6f15
commit
09e2fb03bf
|
@ -2141,8 +2141,8 @@ function url($path = NULL, array $options = array()) {
|
|||
$path = '';
|
||||
}
|
||||
elseif (!empty($path) && !$options['alias']) {
|
||||
$language = isset($options['language']) && isset($options['language']->langcode) ? $options['language']->langcode : '';
|
||||
$alias = drupal_get_path_alias($original_path, $language);
|
||||
$langcode = isset($options['language']) && isset($options['language']->langcode) ? $options['language']->langcode : '';
|
||||
$alias = drupal_get_path_alias($original_path, $langcode);
|
||||
if ($alias != $original_path) {
|
||||
$path = $alias;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,35 @@
|
|||
* Install, update and uninstall functions for the locale module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 locale_install() {
|
||||
require_once DRUPAL_ROOT . '/core/includes/language.inc';
|
||||
|
||||
// We cannot rely on language negotiation hooks here, because locale module is
|
||||
// not enabled yet. Therefore language_negotiation_set() cannot be used.
|
||||
$info = locale_language_negotiation_info();
|
||||
$provider = $info[LOCALE_LANGUAGE_NEGOTIATION_URL];
|
||||
$provider_fields = array('callbacks', 'file', 'cache');
|
||||
$negotiation = array();
|
||||
|
||||
// Store only the needed data.
|
||||
foreach ($provider_fields as $field) {
|
||||
if (isset($provider[$field])) {
|
||||
$negotiation[LOCALE_LANGUAGE_NEGOTIATION_URL][$field] = $provider[$field];
|
||||
}
|
||||
}
|
||||
|
||||
// Enable URL language detection for each (core) configurable language type.
|
||||
foreach (language_types_configurable() as $type) {
|
||||
variable_set("language_negotiation_$type", $negotiation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the path prefixes and domains when enabled.
|
||||
*
|
||||
|
|
|
@ -1640,15 +1640,10 @@ class LocalePathFunctionalTest extends DrupalWebTestCase {
|
|||
$edit = array( "prefix[$langcode]" => $prefix );
|
||||
$this->drupalPost('admin/config/regional/language/configure/url', $edit, t('Save configuration'));
|
||||
|
||||
// Check that the "xx" front page is not available when path prefixes are
|
||||
// not enabled yet.
|
||||
$this->drupalPost('admin/config/regional/language/configure', array(), t('Save settings'));
|
||||
// Check that the "xx" front page is readily available because path prefix
|
||||
// negotiation is pre-configured.
|
||||
$this->drupalGet($prefix);
|
||||
$this->assertResponse(404, t('The "xx" front page is not available yet.'));
|
||||
|
||||
// Enable URL language detection and selection.
|
||||
$edit = array('language[enabled][locale-url]' => 1);
|
||||
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
|
||||
$this->assertText(t('Welcome to Drupal'), t('The "xx" front page is readibly available.'));
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('type' => 'page'));
|
||||
|
@ -2187,7 +2182,6 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
|
|||
$edit = array('prefix[en]' => 'en');
|
||||
$this->drupalPost('admin/config/regional/language/configure/url', $edit, t('Save configuration'));
|
||||
|
||||
|
||||
// Enable browser and URL language detection.
|
||||
$edit = array(
|
||||
'language[enabled][locale-browser]' => TRUE,
|
||||
|
@ -2205,7 +2199,8 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
|
|||
// Access the front page without specifying any valid URL language prefix
|
||||
// and having as browser language preference a non-default language.
|
||||
$http_header = array("Accept-Language: $langcode_browser_fallback;q=1");
|
||||
$this->drupalGet('', array(), $http_header);
|
||||
$language = (object) array('langcode' => '');
|
||||
$this->drupalGet('', array('language' => $language), $http_header);
|
||||
|
||||
// Check that the language switcher active link matches the given browser
|
||||
// language.
|
||||
|
|
|
@ -297,9 +297,11 @@ class PathLanguageTestCase extends DrupalWebTestCase {
|
|||
$this->drupalGet('fr/' . $edit['path[alias]']);
|
||||
$this->assertText($french_node->title, 'Alias for French translation works.');
|
||||
|
||||
// Confirm that the alias is returned by url().
|
||||
// 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');
|
||||
$languages = language_list();
|
||||
$url = url('node/' . $french_node->nid, array('language' => $languages[$french_node->language]));
|
||||
$this->assertTrue(strpos($url, $edit['path[alias]']), t('URL contains the path alias.'));
|
||||
|
|
|
@ -47,11 +47,7 @@ class TranslationTestCase extends DrupalWebTestCase {
|
|||
$edit = array("blocks[locale_$language_type][region]" => 'sidebar_first');
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
|
||||
// Enable URL language detection and selection to make the language switcher
|
||||
// block appear.
|
||||
$edit = array('language[enabled][locale-url]' => TRUE);
|
||||
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
|
||||
$this->assertRaw(t('Language negotiation configuration saved.'), t('URL language detection enabled.'));
|
||||
// Reset static caches in our local language environment.
|
||||
$this->resetCaches();
|
||||
|
||||
$this->drupalLogin($this->translator);
|
||||
|
@ -200,6 +196,7 @@ class TranslationTestCase extends DrupalWebTestCase {
|
|||
$this->drupalLogin($this->admin_user);
|
||||
$edit = array('languages[it][enabled]' => TRUE);
|
||||
$this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
|
||||
$this->resetCaches();
|
||||
$this->drupalLogin($this->translator);
|
||||
|
||||
// Create a Basic page in English.
|
||||
|
@ -258,7 +255,9 @@ class TranslationTestCase extends DrupalWebTestCase {
|
|||
* Reset static caches to make the test code match the client site behavior.
|
||||
*/
|
||||
function resetCaches() {
|
||||
drupal_static_reset('language_list');
|
||||
drupal_static_reset('locale_url_outbound_alter');
|
||||
drupal_static_reset('locale_language_url_rewrite_url');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue