index.html 显示页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function() {
$('#ch').click(function(){
$.ajax({
url: 'index.php',
type: 'post',
datatype: 'json',
data: 'lang=ch',
success:function(msg) {
$('p').text(msg);
}
})
})
$('#us').click(function(){
$.ajax({
url: 'index.php',
type: 'post',
datatype: 'json',
data: 'lang=us',
success:function(msg) {
$('p').text(msg);
}
})
})
})
</script>
</head>
<body>
<p>小明</p>
<input type="button" value="中文" id="ch"/>
<input type="button" value="English" id="us"/>
</body>
</html>
index.php 处理页面
<?php
!isset($_POST['lang']) ? $rs = null : $rs = htmlspecialchars($_POST['lang']);
switch ($rs) {
case 'ch':
$a = 'ch';
break;
default:
$a = 'en';
break;
}
require "lang-{$a}.php";
echo $name;
语言包
英文lang-us.php
<?php
/*
* @Author: xinghuang@hengtiansoft.com
* @Date: 2014-05-23 11:13:22
* @Last Modified by: xinghuang@hengtiansoft.com
* @Last Modified time: 2014-05-23 11:32:33
*/
$name='xiaoming';
中文lang-ch.php
<?php
/*
* @Author: xinghuang@hengtiansoft.com
* @Date: 2014-05-23 11:14:16
* @Last Modified by: xinghuang@hengtiansoft.com
* @Last Modified time: 2014-05-23 11:32:29
*/
$name='小明';