php语⾔切换功能,php简单实现多语⾔切换的⽅法本⽂实例讲述了php简单实现多语⾔切换的⽅法。分享给⼤家供⼤家参考,具体如下:
1.主程序代码:
include "lib/function.php";
>
if(isset($_GET["language"])){
$_SESSION["language"] = $_GET["language"];
}else{
$_SESSION["language"] = getDefalutlanguage();
}
$language_name = getLanguageName($_SESSION["language"]);
include "lang/".$language_name.".inc";
>
$language_array = array_language();
foreach($language_array as $key => $value){
if($_SESSION["language"] == $value){
$selected = "selected = "selected" ";
}else{
$selected = "";
}
>
><?php echo getLanguageName($value);?>;
}
>
if($_GET["language"] == $value){
//$selected = "selected = "selected" ";
}
echo "语⾔:".$_SESSION["language"];
echo "测试:".$name;
>
2. 所包含的语⾔包:English.inc
$name = "name";
>
Chinese.inc
$name = "名字";
>
3. 所包含的function.php
function getVailableLanguage() { $language = array(
"af" => "Afrikaans",
"az" => "Azerbaijani",
"eu" => "Basque",
"be" => "Belarusian",
"be-lat" => "Belarusian latin", "bg" => "Bulgarian",
"bs" => "Bosnian",
"ca" => "Catalan",
"zh" => "Chinese",
//"zh-TW" => "Chinese traditional", //"zh-CN" => "Chinese simplified", "cs" => "Czech",
"da" => "Danish",
"de" => "German",
"el" => "Greek",
"en" => "English",
"es" => "Spanish",
"et" => "Estonian",
"fa" => "Persian",
"fi" => "Finnish",
"fr" => "French",
"gl" => "Galician",
"he" => "Hebrew",
"hi" => "Hindi",
"hr" => "Croatian",
"hu" => "Hungarian",
"id" => "Indonesian",
"it" => "Italian",
"ja" => "Japanese",
"ko" => "Korean",
"ka" => "Georgian",
"lt" => "Lithuanian",
"lv" => "Latvian",
"mk" => "Macedonian",
"mn" => "Mongolian",
"ms" => "Malay",
"nl" => "Dutch",
"no" => "Norwegian",
"pl" => "Polish",
"pt-BR" => "Brazilian portuguese", "pt" => "Portuguese",
"ro" => "Romanian",
"ru" => "Russian",
"si" => "Sinhala",
"sk" => "Slovak",
"sl" => "Slovenian",
"sq" => "Albanian",
"sr-lat" => "Serbian latin",
"sr" => "Serbian",
"sv" => "Swedish",
"th" => "Thai",
"tr" => "Turkish",
"tt" => "Tatarish",
"uk" => "Ukrainian",
);
return $language;
}
function getLanguageName($language) { $languages = getVailableLanguage(); return $languages[$language];
}
function array_language(){
$array_language = array("en","zh");
return $array_language;
}
function getDefalutlanguage(){
return "zh";
}
>
4.所包含的language.js
function changeLanguage(obj) {
var url = document.URL;
var re = re = /[?&]language=[^&]*/;
url = place(re, "");
php语言零基础入门
if (url.indexOf("?") > -1) {
url += "&language=" + obj.value;
} else {
url += "?language=" + obj.value;
}
location.href = url;
}
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数组(Array)操作技巧⼤全》、《PHP数据结构与算法教程》、《PHP数学运算技巧总结》、《php⽇期与时间⽤法总结》、《php⾯向对象程序设计⼊门教程》、《php字符串(string)⽤法总结》、《php+mysql数据库操作⼊门教程》及《php常见数据库操作技巧汇总》
希望本⽂所述对⼤家PHP程序设计有所帮助。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。