From 23b938d6fbb61a538e3554155750c0f8652515ac Mon Sep 17 00:00:00 2001 From: james Date: Tue, 30 Nov 2004 18:34:25 +0000 Subject: [PATCH] setup i18n and multi-language support --- common.inc.php | 93 ++++++++++++++++++++++++++++++++++++++++++-------- config.inc.php | 1 - 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/common.inc.php b/common.inc.php index 100d523..91b9a2f 100644 --- a/common.inc.php +++ b/common.inc.php @@ -3,6 +3,52 @@ require("config.inc.php"); mysql_connect($DBHOST,$DBUSER,$DBPASS); mysql_select_db($DBNAME); +session_start(); + +//find out the fiar year +$q=mysql_query("SELECT * FROM config WHERE var='FAIRYEAR' AND year='0'"); +$r=mysql_fetch_object($q); +$FAIRYEAR=$r->val; +$config['FAIRYEAR']=$FAIRYEAR; + +//now pull the rest of the configuration +$q=mysql_query("SELECT * FROM config WHERE year='$FAIRYEAR'"); +while($r=mysql_fetch_object($q)) +{ + $config[$r->var]=$r->val; +} + +//now get the languages, and make sure we have at least one active language +$q=mysql_query("SELECT * FROM languages WHERE active='Y' ORDER BY langname"); +if(mysql_num_rows($q)==0) +{ + echo "No active languages defined, defaulting to English"; + $config['languages']['en']="English"; +} +else +{ + while($r=mysql_fetch_object($q)) + { + $config['languages'][$r->lang]=$r->langname; + } +} + +//if the user has switched languages, go ahead and switch the session variable +if($_GET['switchlanguage']) +{ + //first, make sure its a valid language: + if($config['languages'][$_GET['switchlanguage']]) + { + $_SESSION['lang']=$_GET['switchlanguage']; + + } + else + { + //invalid language, dont do anything + } + +} + function i18n($str) { @@ -15,7 +61,7 @@ function i18n($str) return $str; else { - $q=mysql_query("SELECT * FROM languages WHERE lang='".$_SESSION['lang']."' AND str='".mysql_escape_string($str)."'"); + $q=mysql_query("SELECT * FROM translations WHERE lang='".$_SESSION['lang']."' AND strmd5='".md5($str)."'"); if($r=@mysql_fetch_object($q)) { if($r->val) @@ -28,7 +74,7 @@ function i18n($str) } else { - mysql_query("INSERT INTO languages (lang,str) VALUES ('".$_SESSION['lang']."','".mysql_escape_string($str)."')"); + mysql_query("INSERT INTO translations (lang,strmd5,str) VALUES ('".$_SESSION['lang']."','".md5($str)."','".mysql_escape_string($str)."')"); echo mysql_error(); return "($str)"; } @@ -44,13 +90,8 @@ function i18n($str) function send_header($title="") { - global $FAIRYEAR; - $q=mysql_query("SELECT * FROM config WHERE year='$FAIRYEAR'"); - while($r=mysql_fetch_object($q)) - { - $config[$r->var]=$r->val; - } - + global $config; + ?> @@ -61,24 +102,46 @@ function send_header($title="")

+ + +1) +{ + echo "
"; + echo ""; + echo "
"; +} + + +?> + +

-Return to SFIAB Development Page +

diff --git a/config.inc.php b/config.inc.php index 0cd6843..32cd2c1 100644 --- a/config.inc.php +++ b/config.inc.php @@ -1,6 +1,5 @@