From f3c2203e2fc179e3f384e0499c34dcff63e792c1 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 7 Dec 2015 17:45:44 +0100 Subject: [PATCH] WEB: Attempt to implement language switcher functionality For some reason the language switching is working one click behind. The goal is to have the page switched instantly, but it doesn't happen now. --- .htaccess | 8 ++++++-- include/Controller.php | 12 +++++------- index.php | 15 +++++++++++++++ templates/lang_menu.tpl | 6 +++--- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.htaccess b/.htaccess index 830fcd42d..a062b1427 100644 --- a/.htaccess +++ b/.htaccess @@ -5,6 +5,10 @@ RewriteEngine On # NOTE: When debugging locally, set this to the directory the site is in RewriteBase / +# Fetch language and put it into Cookie +RewriteCond %{QUERY_STRING} lang=(.*)? +RewriteRule .* - [CO=lang:%1:.scummvm.org] + ## # Images linked directly from the wiki need to work ## @@ -33,7 +37,7 @@ RewriteRule ^(.+)\.php$ $1/? [NS,R=301] # Basic rewrite ## RewriteRule ^([a-z]+)/?$ ?p=$1 - + ## # Compatibility ## @@ -49,7 +53,7 @@ RewriteRule ^(documentation)(/([^/]+))?/? ?p=$1&d=$3 [L] ## RewriteRule ^(feeds)/(atom|rss)/? ?p=$1&f=$2 [L] -## +## # News ## RewriteRule ^(news)(/([0-9]{8}[a-z]?|archive))?/?$ ?p=$1&d=$3 [L] diff --git a/include/Controller.php b/include/Controller.php index 94a3dbbe4..5d5664bc1 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -28,13 +28,6 @@ public function __construct() { global $Smarty; $Smarty = $this->_smarty; - /** - * Multilanguage suppot - */ - if (empty($_SESSION['lang']) || !empty($_GET['lang'])) { - $_SESSION['lang'] = empty($_GET['lang']) ? '' : $_GET['lang']; - } - global $lang; $this->_smarty->template_dir = array("templates_$lang", 'templates'); @@ -85,12 +78,17 @@ public function __construct() { if (!ExceptionHandler::skipMenus()) { $menus = MenuModel::getAllMenus(); } + + # Construct lang URL + $pageurl = preg_replace('/\?lang=[a-z]*$/', '', $_SERVER['REQUEST_URI']); + /* Set up the common variables before displaying. */ $vars = array( 'release' => RELEASE, 'baseurl' => URL_BASE, 'heroes_num' => HEROES_NUM, 'menus' => $menus, + 'pageurl' => $pageurl, ); $this->_smarty->assign($vars); } diff --git a/index.php b/index.php index e13bbd3ba..e3ae612b6 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,19 @@
  • Language