PHP通过js做简体和繁体切换_成都网站搭建
做中文繁体的网站可以通过js语言包去做简体到繁体的切换,不用像中文转英文怕用插件机翻让人摸不着头脑,下面介绍一下具体实现方法:这里用的是Thinkphp框架在通用控制器HomeController.class.php中 保存一个cookie 记录当前的语言,?phpfunction__construct(){parent::__construct();$zh_web_lang=array();$lang=cookie(zh_web_lang);//谁放在前面,谁为默认的显示。if($lang==jianti){$zh_web_lang[hreflang]=s;$zh_web_lang[atuolang]=t;$zh_web_lang[lang]=fanti;$zh_web_lang[html]=简体中文;}else{$zh_web_lang[hreflang]=t;$zh_web_lang[atuolang]=s;$zh_web_lang[lang]=jianti;$zh_web_lang[html]=繁體中文;}$this-assign(zh_web_lang,$zh_web_lang);//输出默认语言}2创建一个方法用于切换cookie?phppublicfunctiontrunlang(){if(IS_POST){$lang=cookie(zh_web_lang);if($lang==jianti){cookie(zh_web_lang,fanti);}else{cookie(zh_web_lang,jianti);}}else{$this-redirect(Index/index);}}3.在前端文件中用js去切换语言ahref=javascript:zh_lang({$zh_web_lang.hreflang});id=zh_langdata-lang={$zh_web_lang.lang}{$zh_web_lang.html}/ascripttype=text/javascriptsrc=/Public/js/lang.js?v=2/scriptscripttype=text/javascript//简体繁體中文切换functionzh_lang(go){$.ajax({url:{:U(Index/trunlang)},type:POST,cache:false,success:function(){vartran_a=$(#zh_lang);if(tran_a.attr(data-lang)==fanti){//转换成简体tran_a.attr(href,javascript:zh_lang(t););tran_a.attr(data-lang,jianti);tran_a.html(繁體中文);}else{//转换成繁體tran_a.attr(href,javascript:zh_lang(s););tran_a.attr(data-lang,fanti);tran_a.html(简体中文);}zh_tran(go);}});}window.onload=$(function(){zh_tran({$zh_web_lang.atuolang});});/script上面的引入的js文件如下httpss://github.com/Irrelon/jquery-lang-js如果简体和繁体的切换标识需要分开的,可以把上面的a标签修改成下面的即可liclass={:$zh_web_lang[atuolang]==s?on:}aifcondition=$zh_web_lang[atuolang]eqthref=javascript:zh_lang({$zh_web_lang.hreflang},j);/ifclass=zh_langdata-lang={$zh_web_lang.lang}{$Think.lang.Zh-cn}/a/liliclass={:$zh_web_lang[atuolang]==t?on:}aifcondition=$zh_web_lang[atuolang]eqshref=javascript:zh_lang({$zh_web_lang.hreflang},f);/ifclass=zh_langdata-lang={$zh_web_lang.lang}{$Think.lang.Tw-cn}/a/li这样就能实现全站文字简体转成繁体,缺点就是图上的文字要单独切成文字,不能做成和图片一体的,还有就是个别文字会出现没有转译,还是简体的情况,但是作为同种同源的字体大部分人还是能看懂。优点就是不用做两个后台对资料进行两次输入还是比较方便的,不像中文转译英文,后台录入比用插件好,最起码意思不会乱,搞得别人看不懂。1.下面是简体的效果:
2.点击切换效果:
切换页面依然保持着繁体效果,以前介绍过通过谷歌插件中文切换英文也是通过js实现的,每次切换页面都收从中文变成英文体验不好。还有一种通过接口去翻译后台输出的每一句文字,可以解决这个问题,比较麻烦。
转英文具体可以:httpss://gtranslate.io/#pricing可以在这里了解相关的介绍
PHP通过js做简体和繁体切换_成都网站搭建 https://cdnanqi.cn/wangzhanzhizuo/11276.html
- SEO推广 互联网推广就是一个烧钱的主,玩不了也是死seo推广-雅安SEO
- 【SEO优化效果】重视网站优化细节,就要重视seo优化影响的方方面面-隆昌SEO优化
- 网站优化SEO方案设计(网站优化SEO方案设计案例)
- 营销型网站如何做好网站内容运营?_宜宾seo优化
- 网站建设经验:如何撰写引人入胜的网站内容_宜宾做网站
- 百度推广开户|百度推广费用|百度推广流程_成都竞价托管
- SEO优化排名软件运营(SEO排名优化哪里好)
- 破局与创新:品牌策划公司的智胜之道_成都网站建设
- 利用SEO优化的方式删除企业负面新闻-成都seo优化-成都网站优化
- 作为一名SEO外链专员应提升自己在SEO方面的能力-成都seo优化-成都网站优化