From 535b656a6f73fafc984a872450ef05fa6ea3115f Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Fri, 21 Dec 2012 14:10:51 +0000 Subject: add test file for browser language --- langs.inc.php | 6 ++++-- test/lang.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/langs.inc.php b/langs.inc.php index 23a207367..57a32fc0b 100644 --- a/langs.inc.php +++ b/langs.inc.php @@ -95,10 +95,11 @@ function domain_redirect($host, $domains_lang, $vhost) * @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 + * @param boolean $do_redirect * * @return string */ -function relocate($langs, $page = '', $default_locale = 'en', $force_accept_language = null) +function relocate($langs, $page = '', $default_locale = 'en', $force_accept_language = null, $do_redirect = true) { require_once 'localeDetection.class.php'; @@ -108,9 +109,10 @@ function relocate($langs, $page = '', $default_locale = 'en', $force_accept_lang $relocate = sprintf('/%s/%s', $locale->getCompatibleLocale(), $page); $relocate = str_replace('//', '/', $relocate); - if ('cli' != PHP_SAPI) { + if ('cli' != PHP_SAPI && do_redirect) { header('Location: ' . $relocate); } + return $relocate; } diff --git a/test/lang.php b/test/lang.php index e86dbd553..bf749217d 100644 --- a/test/lang.php +++ b/test/lang.php @@ -6,4 +6,4 @@ include_once '../lib/localeDetection.class.php'; include_once '../langs.inc.php'; echo 'Accept-Language: ', $_SERVER['HTTP_ACCEPT_LANGUAGE'], "\n\n"; -echo "Relocate `community` with `en` as a default: ", relocate($langs, 'community'), "\n"; +echo "Relocate `community` with `en` as a default: ", relocate($langs, 'community', 'en', null, false), "\n"; -- cgit v1.2.1