From: <ste...@us...> - 2012-07-07 04:09:29
|
Revision: 11373 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=11373&view=rev Author: stephenjust Date: 2012-07-07 04:09:23 +0000 (Sat, 07 Jul 2012) Log Message: ----------- [stkaddons] Remove the necessity for refreshing the page after changing languages (this also means search engines should now be able to pick up translated pages) Modified Paths: -------------- stkaddons/trunk/include/locale.php stkaddons/trunk/include/menu.php Modified: stkaddons/trunk/include/locale.php =================================================================== --- stkaddons/trunk/include/locale.php 2012-07-06 19:29:48 UTC (rev 11372) +++ stkaddons/trunk/include/locale.php 2012-07-07 04:09:23 UTC (rev 11373) @@ -31,21 +31,21 @@ // Set language cookie if it is not set if(!isset($_COOKIE['lang']) && !isset($_GET['lang'])) { - setcookie('lang', 'en_EN', $timestamp_expire); + setcookie('lang', 'en_US', $timestamp_expire); + putenv('LC_ALL=en_US.UTF-8'); + setlocale(LC_ALL, 'en_US.UTF-8'); } -if (isset($_GET['lang'])) { // If the user has chosen a language +elseif (isset($_GET['lang'])) +{ // If the user has chosen a language setcookie('lang', $_GET['lang'], $timestamp_expire); - // Need to reload page to make sure translations are visible - echo <<< EOF -<html> - <head> - <meta http-equiv="refresh" content="0;URL=$page_url"> - </head> -</html> -EOF; - exit; + putenv('LC_ALL='.$_GET['lang'].'.UTF-8'); + setlocale(LC_ALL, $_GET['lang'].'.UTF-8'); } -if (isset($_COOKIE['lang'])) setlocale(LC_ALL, $_COOKIE['lang'].'.UTF-8'); +else +{ + putenv('LC_ALL='.$_COOKIE['lang'].'.UTF-8'); + setlocale(LC_ALL, $_COOKIE['lang'].'.UTF-8'); +} bindtextdomain('translations', ROOT.'locale'); textdomain('translations'); Modified: stkaddons/trunk/include/menu.php =================================================================== --- stkaddons/trunk/include/menu.php 2012-07-06 19:29:48 UTC (rev 11372) +++ stkaddons/trunk/include/menu.php 2012-07-07 04:09:23 UTC (rev 11373) @@ -108,10 +108,15 @@ ); for ($i = 0; $i < count($langs); $i++) { $url = $_SERVER['REQUEST_URI']; + // Generate the url to change the language if (strstr($url,'?') === false) $url .= '?lang='.$langs[$i][0]; - else + else { + // Make sure any existing instances of lang are removed + $url = preg_replace('/(&)*lang=[a-z_]+/i',NULL,$url); $url .= '&lang='.$langs[$i][0]; + $url = str_replace('?&','?',$url); + } printf("\t\t\t<li class=\"flag\"><a href=\"%s\" style=\"background-position: %dpx %dpx;\">%s</a></li>\n",$url,$langs[$i][1],$langs[$i][2],$langs[$i][3]); } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |