4 网站多语言替换方法

<?php
if($_POST['submit']){
	define('ROOT_PATH', '');
	$chnOldData	=	file_get_contents(ROOT_PATH.'langs/lang-Chinese.php');
	$engOldData	=	file_get_contents(ROOT_PATH.'langs/lang-English.php');
	foreach ($_POST['tagNamePhp'] as $k=>$v){
		if(!empty($_POST['tagNamePhp'][$k])){
			$match	=	strpos($chnOldData,$_POST['tagNamePhp'][$k]);
//			var_dump($_POST['tagNamePhp'][$k]);
//			var_dump($match);
//			var_dump($chnOldData);
 
			if($match==false){
			$addChnData		.=	'case "'.$_POST['tagNamePhp'][$k].'": return \''.$_POST['tagNameChn'][$k].'\';';
			$addEngData		.=	'case "'.$_POST['tagNamePhp'][$k].'": return \''.$_POST['tagNameEng'][$k].'\';';
			}else{
				if(!empty($_POST['tagNamePhp'][$k])){
					$failAddStr		.=	$_POST['tagNamePhp'][$k].'<br />';
				}
				continue;
			}
		}
	}
 
	$mark		=	"/*{[|mark position,do not delete|]}*/";
	if(!empty($addChnData)){
		$chnNewData	=	str_replace($mark,$addChnData.$mark,$chnOldData);
		file_put_contents(ROOT_PATH.'langs/lang-Chinese.php',$chnNewData);
	}
	if(!empty($addEngData)){
		$engNewData	=	str_replace($mark,$addEngData.$mark,$engOldData);
		file_put_contents(ROOT_PATH.'langs/lang-English.php',$engNewData);
	}
	if(empty($failAddStr)){
		echo '成功';
	}else{
		echo '<font color="#f00">'.$failAddStr.'</font>上面这些PHP标签因为重复,没有添加成功,其它添加成功';
	}
}
?>
<form action="" method="post">
<table>
<tr><td colspan="2">REPALCE LANGUAGE</td></tr>
<?php for ($i=1;$i<=10; $i++){?>
<tr>
<td>TAG Name IN PHP</td><td><input type="text" name="tagNamePhp[]"></td>
<td>TAG Name IN ENGLISH</td><td><input type="text" name="tagNameEng[]"></td>
<td>TAG Name IN CHINESE</td><td><input type="text" name="tagNameChn[]"></td>
<?php }?>
<tr><td colspan="2"><input type="submit" name="submit" value="submit"></td></tr>
</table>
</form>
Example: <br />
In php file you can write like this: <?php echo '&lt;?php echo _t(\'_hello\'); ?&gt;'; ?>

Related posts:

Leave a Reply

Your email address will not be published.