summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/language.inc14
-rw-r--r--modules/locale/locale.test8
-rw-r--r--modules/locale/tests/locale_test.module3
3 files changed, 21 insertions, 4 deletions
diff --git a/includes/language.inc b/includes/language.inc
index b7057f2a1..20909f5a6 100644
--- a/includes/language.inc
+++ b/includes/language.inc
@@ -349,7 +349,10 @@ function language_provider_invoke($provider_id, $provider = NULL) {
$results[$provider_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
}
- return $results[$provider_id];
+ // Since objects are resources we need to return a clone to prevent the
+ // provider cache to be unintentionally altered. The same providers might be
+ // used with different language types based on configuration.
+ return !empty($results[$provider_id]) ? clone($results[$provider_id]) : $results[$provider_id];
}
/**
@@ -380,15 +383,18 @@ function language_initialize($type) {
// first valid language found.
$negotiation = variable_get("language_negotiation_$type", array());
- foreach ($negotiation as $id => $provider) {
- $language = language_provider_invoke($id, $provider);
+ foreach ($negotiation as $provider_id => $provider) {
+ $language = language_provider_invoke($provider_id, $provider);
if ($language) {
+ $language->provider = $provider_id;
return $language;
}
}
// If no other language was found use the default one.
- return language_default();
+ $language = language_default();
+ $language->provider = LANGUAGE_NEGOTIATION_DEFAULT;
+ return $language;
}
/**
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index ca945569a..db0bead1e 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -2118,6 +2118,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
'path' => 'admin/config',
'expect' => $default_string,
+ 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > DEFAULT: no language prefix, UI language is default and the browser language preference setting is not used.',
),
@@ -2126,6 +2127,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
'path' => "$language/admin/config",
'expect' => $language_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > DEFAULT: with language prefix, UI language is switched based on path prefix',
),
@@ -2134,6 +2136,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_BROWSER),
'path' => 'admin/config',
'expect' => $language_browser_fallback_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_BROWSER,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > BROWSER: no language prefix, UI language is determined by browser language preference',
),
@@ -2142,6 +2145,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_BROWSER),
'path' => "$language/admin/config",
'expect' => $language_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > BROWSER: with langage prefix, UI language is based on path prefix',
),
@@ -2150,6 +2154,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_BROWSER, LANGUAGE_NEGOTIATION_DEFAULT),
'path' => 'admin/config',
'expect' => $default_string,
+ 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
'http_header' => $http_header_blah,
'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
),
@@ -2177,6 +2182,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'locale_language_negotiation_url_part' => LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN,
'path' => 'admin/config',
'expect' => $default_string,
+ 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (DOMAIN) > DEFAULT: default domain should get default language',
),
@@ -2188,6 +2194,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'locale_test_domain' => $language_domain,
'path' => 'admin/config',
'expect' => $language_string,
+ 'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (DOMAIN) > DEFAULT: domain example.cn should switch to Chinese',
),
@@ -2211,6 +2218,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
}
$this->drupalGet($test['path'], array(), $test['http_header']);
$this->assertText($test['expect'], $test['message']);
+ $this->assertText(t('Language negotiation provider: @name', array('@name' => $test['expected_provider'])));
}
/**
diff --git a/modules/locale/tests/locale_test.module b/modules/locale/tests/locale_test.module
index 14a2588dd..2af50a69d 100644
--- a/modules/locale/tests/locale_test.module
+++ b/modules/locale/tests/locale_test.module
@@ -32,6 +32,9 @@ function locale_test_boot() {
*/
function locale_test_init() {
locale_test_store_language_negotiation();
+ if (isset($GLOBALS['language']) && isset($GLOBALS['language']->provider)) {
+ drupal_set_message(t('Language negotiation provider: @name', array('@name' => $GLOBALS['language']->provider)));
+ }
}
/**