Skip to content

Commit

Permalink
WEB: Attempt to implement language switcher functionality
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sev- committed Jan 16, 2016
1 parent 3edc0d9 commit f3c2203
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
8 changes: 6 additions & 2 deletions .htaccess
Expand Up @@ -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
##
Expand Down Expand Up @@ -33,7 +37,7 @@ RewriteRule ^(.+)\.php$ $1/? [NS,R=301]
# Basic rewrite
##
RewriteRule ^([a-z]+)/?$ ?p=$1

##
# Compatibility
##
Expand All @@ -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]
Expand Down
12 changes: 5 additions & 7 deletions include/Controller.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions index.php
@@ -1,4 +1,19 @@
<?php

This comment has been minimized.

Copy link
@RichieSams

RichieSams Jan 19, 2016

Contributor

Perhaps the "click behind" bug is caused because we never call session_start()

http://php.net/manual/en/function.session-start.php

When I get home I can clone the repo and try it out.

This comment has been minimized.

Copy link
@bluegr

bluegr Jan 20, 2016

Member

That is the reason, yes. I've got a local fix for this

This comment has been minimized.

Copy link
@RichieSams

RichieSams Jan 21, 2016

Contributor

I made a pull request to address the issue

global $lang;

/**
* Multilanguage suppot
*/
if (empty($_SESSION['lang']) || !empty($_GET['lang'])) {
$_SESSION['lang'] = empty($_GET['lang']) ? '' : $_GET['lang'];
}
if (empty($_SESSION['lang']) || !empty($_COOKIE['lang'])) {
$_SESSION['lang'] = empty($_COOKIE['lang']) ? '' : $_COOKIE['lang'];
}

$lang = $_SESSION['lang'];

/* Load the configuration. */
require_once('include/config.inc.php');
/* Set up the include path. */
Expand Down
6 changes: 3 additions & 3 deletions templates/lang_menu.tpl
Expand Up @@ -3,9 +3,9 @@
<ul id="langmenu">
<li><a href="">Language</a>
<ul>
<li><a href="?lang="><code class="text-badge">EN</code>English</a></li>
<li><a href="?lang=de"><code class="text-badge">DE</code>German</a></li>
<li><a href="?lang=ru"><code class="text-badge">RU</code>Russian</a></li>
<li><a href="{$pageurl}?lang="><code class="text-badge">EN</code>English</a></li>
<li><a href="{$pageurl}?lang=de"><code class="text-badge">DE</code>German</a></li>
<li><a href="{$pageurl}?lang=ru"><code class="text-badge">RU</code>Russian</a></li>
</ul>
</li>
</ul>
Expand Down

1 comment on commit f3c2203

@sev-
Copy link
Member Author

@sev- sev- commented on f3c2203 Jan 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accepted the pull request, but it did not help anyway.

Please sign in to comment.