If we may want to support multilanguages to our web we keep all languages as variables in different files. Usually we provide them in a specific folder for practicality. Below is the screenshot using two languages as choices:
here is the scripts:
index.php
<?php
session_start();
$_SESSION['lang'] = $a;
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<form name="form1" method="post" action="?lang=">
Choose Language :
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<?php
if(($_GET['lang'] == "english") || (empty($_GET['lang']))) {
?>
<option value="?lang=indonesian">Indonesian</option>
<option value="?lang=english" selected>English</option>
<?php
} else {
?>
<option value="?lang=indonesian" selected>Indonesian</option>
<option value="?lang=english">English</option>
<?php
} // end else
?>
</select>
</form>
<p>
<?php
if($_GET['lang'] == "english") {
$a = include "lang/eng.php";
} else if ($_GET['lang'] == "indonesian") {
$a = include "lang/ind.php";
} else {
$a = include "lang/eng.php";
}
print "$language $home<br>$faq<br>$tes";
?>
eng.php (put it in subfolder lang)
<?php
$home = "Home";
$faq = "About Us";
$tes = "Help";
?>
ind.php (put it in subfolder lang)
<?php
$home = "Menu Utama";
$faq = "Tentang Kami";
$tes = "Bantuan";
?>
you may download the scripts here (2kb).
No comments:
Post a Comment