I want to make my PHP website into a multiple language website, with exactly two languages (English, Turkish).
At the top of the web page, there are two icons, one for English and the other for Turkish. When a user clicks on Turkish icon how can I detect that Turkish is selected?
<div><a href="" title="English" id="English" class="active_lang"><img src="images/united-kingdom.png" class= "active" style="float: right; width: 24px;height:24px ;padding: 4px"> </a>
<a href="" title="Turkish" id="Turkish"><img src="images/turkey.png" style="float: right; width: 24px;height:24px; padding: 4px"> </a>
</div>
$arrLang['alert_admin_email_wrong']='kullanci email yanliştır '
$arrLang['alert_admin_email_wrong']='your email is wrong '
The easiest way to do that is to create an cookie when the user clicks on the wanted language. As for the array i would split it per language
$arrLang['en']['alert_admin_email_wrong'] = 'text here';
$arrLang['tr']['alert_admin_email_wrong'] = 'text here turkish';
As for language selection would do this on the webpage
<a href="?langSelect=en">English</a><a href="?langSelect=tr">Turkish</a>
On the language selection page :
$defaultLanguage = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en'; //default to english language
if(isset($_GET['langSelect'])){
//allow only 2 for now ( english / turkish)
$langForSelection = "";
switch($_GET['langSelect']){
case 'en':
$langForSelection = 'en';
break;
case 'tr':
$langForSelection = 'tr';
break;
default:
break;
}
if(isset($langForSelection)){
setcookie('lang',$langForSelection,time()+24*7*60*60);//set cookie to expire in 7 days
}
}
After to show the variables
echo $arrLang[$defaultLanguage]['alert_admin_email_wrong'];