|
|
|
|
|
|
| |
Assuming you've got the translation for everything (every phrase/paragraph) you want on your page, a simple, 3-option language check will present your page in your visitor's language.
1.: On 1st visit, the code will check the browser language of the visitor and display your page accordingly.
2.: If the visitor prefers another language, he/she can choose it from a drop-down menu.
3.: Either way, a cookie is set recording the visitor's chosen language so as to display automatically in this language on subsequent visits. This is the first check to be made by the code on any visit.
1.XXXXXX First, you need the language-selection include (langfile.php):
| <?php
/*Check_if_user_has_changed_language: */
if(isset($lang)){/*If_so:*/
setcookie("ling",$lang,time()-60*60*24*365,"/",".YourWebSite.com",0);/*Wipe_previous_cookie*/
setcookie("ling",$lang,time()+60*60*24*365,"/",".YourWebSite.com",0);/*Whatever_the_means_lang_has_been_stored,_store_latest_lang_in_new_cookie:*/
//echo "<script language=\"JavaScript\">alert('Selected language=$lang')</script>";/*UnComment_to_check*/
}else{/*If_user_has_NOT_changed_language:*/
if(isset($_COOKIE['ling'])){/*Check_if_user-language_cookie_is_set._If_so:*/
$lang=$_COOKIE['ling'];
setcookie("ling",$lang,time()-60*60*24*365,"/",".YourWebSite.com",0);/*Wipe_previous_cookie*/
setcookie("ling",$lang,time()+60*60*24*365,"/",".YourWebSite.com",0);
//echo "<script language=\"JavaScript\">alert('Cookie language=$lang')</script>";/*UnComment_to_check*/
}else{/*If_user-language_neither_selected_nor_in_cookie,_choose_browser_language:*/
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
setcookie("ling",$lang,time()+60*60*24*365,"/",".YourWebSite.com",0);
//echo "<script language=\"JavaScript\">alert('Your browser language=$lang')</script>";/*UnComment_to_check*/
}
}
?> | |
2.XXXXXX A simple switch/case function will provide the language content to the server, easiest to keep in its own script (langs.php), example:
| <?php
switch ($lang){ /*The switch/case function is used to select the $lang language variable that the visitor has selected, or that has been drawn from his cookie or his browser language */
//-------ENGLISH
case 'en':
$Title = "Multilingual Web pages.";
$Mdesc = "Languages, Translation, multilingual multimedia";
$Mkw = "translation, multilingual, audio, video, communication, translate, voiceover";
$intro = "Offer yourself a multilingual website accessible to the REST of the world too!";
// etc.
break;
//-------FRANCAIS
case 'fr':
$Title = "Pages Web multilingue, rich media, multimedia, etc.";
$Mdesc = "toutes les langues en une seule page web";
$Mkw = "langues, traduction, multilingue, communication, traduire";
$intro = "Offrez-vous un site Web accessible au RESTE du monde aussi !";
// etc.
break;
//-------
}
?> | |
3.XXXXXX Then, at the top of your target page (index.php), call the language-select include:
| include ($path."langfile.php"); ?> <!-- includes cookie -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head id="Head">
<?php include ($path."langs.php"); ?>
<title><?php echo "$Title" ?></title>
</head>
<body> <!-- text called from "langs.php" variables -->
<!-- ...etc.etc. -->
</body> | | |
|
| PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | Authentication script to authenticate users in Active Directory through LDAP. Categories : LDAP, Authentication, Cookies, PHP | | | cookie Categories : Cookies, PHP | | | Simple PHP cookie counter Categories : PHP, Cookies, Beginner Guides | | | Example voting script. Lets people enter suggestions and vote for existing ones. Categories : MySQL, PHP, Cookies, Complete Programs, Databases | | | how to check if a string contains a letter from a different language? Categories : PHP, Regexps, Languages | | | Function that allows a Javascript cookie to be set after HTML has been outputted to the page.
Categories : PHP, Java Script, Cookies, HTML and PHP | | | The Best Authorize Categories : PHP, MySQL, Cookies | | | Secure Login Categories : PHP, MySQL, Cookies, Security | | | Simple Cookie example Categories : PHP, Beginner Guides, Cookies | | | With this class you can use cookies with chips Categories : PHP, Cookies | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | How to make sure a that $foo is from a cookie and not from the URI. Categories : PHP, Variables, Global Variables, Cookies | | | multilingual website Categories : PHP, Languages, Sessions | |
|
|
|