/*
网站语言英文解决方案——通过改变缓冲区来实现
功能:根据cookie判断用户选择的语言,默认为中文(不执行替换),当用户在页面中选择英语时候,则通过JS写入cookie语言状态码,此页面通过判断改cookie来判断是否进行语言翻译.
说明:在前端通过JS判断用户选择的语言,用户选择英文时候,JS写入cookie语言状态为‘EN’,后台程序通过判断cookie保存的语言编码执行语言翻译操作.
作者:aibhsc
使用方法:在下面文件中加入要替换的中英文,然后在程序入口文件引用该文件即可.
应用场景:对于企业网站英文不常使用,修改程序与数据库代价太高,但又必须要英文的网站,可以尝试使用此程序.
*/
<?php //通过一维数组存储语言包,节省空间,方便键的处理,注意:①键值别错位;②长字符串优先 //语言包,把要翻译的内容放在此处——start $cn[]='用户登录';$en[]='UserLogin'; $cn[]='登录';$en[]='Login'; $cn[]='注册';$en[]='Reg'; $cn[]='首页';$en[]='Home'; $cn[]='查看';$en[]='View'; $cn[]='去向';$en[]='Local'; $cn[]='钻重';$en[]='Weight'; $cn[]='国检';$en[]='NGTC'; $cn[]='';$en[]=''; //语言包——end //全局定义,引用语言包. $GLOBALS['global_CN']=&$cn; $GLOBALS['global_EN']=&$en; $GLOBALS['global_lang']=$_COOKIE['user_lang']?$_COOKIE['user_lang']:'CN'; cache(); //执行语言翻译操作 function cache(){ ob_start(array($this, "AutoCache")); //不懂这行请查看PHP手册call_user_func里面第四个例子“Example #4” } function cn2en($body){ //参数:$body 要翻译的内容 ;$arr_cn 中文语言包;$arr_en 英文语言包; 返回值:替换后的字符串 //当两个语言包键值不对,则返回原值不进行任何操作. if(count($GLOBALS['global_CN'])<>count($GLOBALS['global_EN'])){return $body;} //当用户选择英文时,则将文档中的中文根据语言包来替换为英文 if($GLOBALS['global_lang']=='EN'){$body=str_ireplace($GLOBALS['global_CN'],$GLOBALS['global_EN'],$body);} return $body; } function AutoCache($contents){ $contents = cn2en($contents); //执行语言翻译 return $contents; } ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
