aboutsummaryrefslogtreecommitdiffstats
path: root/langs.inc.php
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-08-17 14:13:01 +0000
committerRomain d'Alverny <rda@mageia.org>2012-08-17 14:13:01 +0000
commitda48cc763775981904730c87ce0524c67cc611e0 (patch)
treeea8ae692f3f97ca04acd3d33f9882e506e59cd99 /langs.inc.php
parent399b91bbca4997fbbbf36a06649be15dd53fd2c2 (diff)
downloadwww-da48cc763775981904730c87ce0524c67cc611e0.tar
www-da48cc763775981904730c87ce0524c67cc611e0.tar.gz
www-da48cc763775981904730c87ce0524c67cc611e0.tar.bz2
www-da48cc763775981904730c87ce0524c67cc611e0.tar.xz
www-da48cc763775981904730c87ce0524c67cc611e0.zip
Fix language redirection (see bug 7091)
- modify relocate() function in langs.inc.php - modify ChooseLocale class constructor in localeDetection.class.php - we currently use ll-cc language tag format (instead of ll-CC, which ChooseLocale strictly expects until now)
Diffstat (limited to 'langs.inc.php')
-rw-r--r--langs.inc.php22
1 files changed, 13 insertions, 9 deletions
diff --git a/langs.inc.php b/langs.inc.php
index d9e1d6ecc..e39afa3f9 100644
--- a/langs.inc.php
+++ b/langs.inc.php
@@ -88,26 +88,30 @@ function domain_redirect($host, $domains_lang, $vhost)
/**
* Redirect to a localized path, after browser Accept-Language prefs.
+ * Return the path.
+ * Do not exit the process.
*
* @param array $langs list of languages
* @param string $page optional path to which we want to redirect
* @param string $default_locale
+ * @param string $force_accept_language replace remote browser HTTP_ACCEPT_LANGUAGE request header
*
- * @return void
+ * @return string
*/
-function relocate($langs, $page = '', $default_locale = 'en')
+function relocate($langs, $page = '', $default_locale = 'en', $force_accept_language = null)
{
require_once 'localeDetection.class.php';
- $locale = new ChooseLocale(array_keys($langs));
-
+ $locale = new ChooseLocale(array_keys($langs), $force_accept_language);
$locale->setDefaultLocale($default_locale);
- header(str_replace('//', '/', sprintf('Location: /%s/%s',
- $locale->getCompatibleLocale(),
- $page
- )));
- die;
+ $relocate = sprintf('/%s/%s', $locale->getCompatibleLocale(), $page);
+ $relocate = str_replace('//', '/', $relocate);
+
+ if ('cli' != PHP_SAPI) {
+ header('Location: ' . $relocate);
+ }
+ return $relocate;
}
/**