forked from science-ation/science-ation
setup i18n and multi-language support
This commit is contained in:
parent
ace55ad45a
commit
23b938d6fb
@ -3,6 +3,52 @@ require("config.inc.php");
|
|||||||
mysql_connect($DBHOST,$DBUSER,$DBPASS);
|
mysql_connect($DBHOST,$DBUSER,$DBPASS);
|
||||||
mysql_select_db($DBNAME);
|
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)
|
function i18n($str)
|
||||||
{
|
{
|
||||||
@ -15,7 +61,7 @@ function i18n($str)
|
|||||||
return $str;
|
return $str;
|
||||||
else
|
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=@mysql_fetch_object($q))
|
||||||
{
|
{
|
||||||
if($r->val)
|
if($r->val)
|
||||||
@ -28,7 +74,7 @@ function i18n($str)
|
|||||||
}
|
}
|
||||||
else
|
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();
|
echo mysql_error();
|
||||||
return "<font color=red>($str)</font>";
|
return "<font color=red>($str)</font>";
|
||||||
}
|
}
|
||||||
@ -44,13 +90,8 @@ function i18n($str)
|
|||||||
|
|
||||||
function send_header($title="")
|
function send_header($title="")
|
||||||
{
|
{
|
||||||
global $FAIRYEAR;
|
global $config;
|
||||||
$q=mysql_query("SELECT * FROM config WHERE year='$FAIRYEAR'");
|
|
||||||
while($r=mysql_fetch_object($q))
|
|
||||||
{
|
|
||||||
$config[$r->var]=$r->val;
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
||||||
@ -61,24 +102,46 @@ function send_header($title="")
|
|||||||
|
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<?
|
<?
|
||||||
echo "<h1>".i18n($config['fairname'])."</h1>";
|
echo "<h1>".i18n($config['FAIRNAME'])."</h1>";
|
||||||
?>
|
?>
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="left">
|
<div id="left">
|
||||||
<ul class="mainnav">
|
<ul class="mainnav">
|
||||||
<li><a href="register_participants.php">Participant Registration</a></li>
|
<li><a href="register_participants.php"><?=i18n("Participant Registration")?></a></li>
|
||||||
<li><a href="register_judges.php">Judges Registration</a></li>
|
<li><a href="register_judges.php"><?=i18n("Judges Registration")?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
<ul class="mainnav">
|
<ul class="mainnav">
|
||||||
<li><a href="admin/">Fair Administration</a></li>
|
<li><a href="admin/"><?=i18n("Fair Administration")?></a></li>
|
||||||
<li><a href="config/">SFIAB Configuration</a></li>
|
<li><a href="config/"><?=i18n("SFIAB Configuration")?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<?
|
||||||
|
|
||||||
|
if(count($config['languages'])>1)
|
||||||
|
{
|
||||||
|
echo "<form name=languageselect method=GET action=\"".$_SERVER['PHP_SELF']."\">";
|
||||||
|
echo "<select name=switchlanguage onChange=\"document.forms.languageselect.submit()\">\n";
|
||||||
|
foreach($config['languages'] AS $key=>$val)
|
||||||
|
{
|
||||||
|
if($_SESSION['lang']==$key) $selected="selected"; else $selected="";
|
||||||
|
|
||||||
|
echo "<option $selected value=\"$key\">$val</option>";
|
||||||
|
}
|
||||||
|
echo "</select>";
|
||||||
|
echo "</form>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<p class="aligncenter">
|
<p class="aligncenter">
|
||||||
<a href="http://www.sfiab.ca/">Return to SFIAB Development Page</a>
|
<a href="http://www.sfiab.ca/"><?=i18n("Return to SFIAB Development Page")?></a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?
|
<?
|
||||||
$SFIABDIRECTORY= "sfiab/";
|
$SFIABDIRECTORY= "sfiab/";
|
||||||
$FAIRYEAR= 2005;
|
|
||||||
$DBHOST= "localhost";
|
$DBHOST= "localhost";
|
||||||
$DBNAME= "sfiab";
|
$DBNAME= "sfiab";
|
||||||
$DBUSER= "sfiab";
|
$DBUSER= "sfiab";
|
||||||
|
Loading…
Reference in New Issue
Block a user