深圳PHP培训
达内深圳罗湖中心

185-8886-4961

热门课程

【达内PHP教程】如何实现php多语言切换?

  • 时间:2016-08-23
  • 发布:深圳PHP培训班
  • 来源:达内新闻

深圳PHP培训(sz.php.tedu.cn)专家分享一下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 = "";   }   ?>   >;     }   ?>

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 = url.replace(re, "");

if (url.indexOf("?") > -1) {

url += "&language=" + obj.value;

} else {

url += "?language=" + obj.value;

}

location.href = url;

}

希望以上内容对你有所帮助!深圳达内PHP培训有着国内首家完整的移动PHP课程体系,高度专注PHP前沿技术。深圳PHP培训项目全部来自于真实的企业项目,单独项目代码量超过 6万行。深圳PHP培训机构为了让学员尽快的进入到企业开发的项目中,深圳达内PHP培训使用自主开发的产品和为客户定制的企业产品为案例,大批深圳PHP培训开发学员都从中收益。

上一篇:【达内PHP教程】php动态网页如何转换成html?
下一篇:【达内PHP教程】php加密解密类有何技巧?

opcache让php如虎添翼_深圳PHP培训

YurunPHP —— 简单易用的开源 PHP 框架

PHP 5 到 PHP 7 性能评测

Yii 快速,安全,专业的PHP框架

选择城市和中心
贵州省

广西省

海南省

台湾