微信小程序简繁体切换如何实现
在网站上切换简体和繁体是很常见的。如果不考虑搜索引擎,一个JS就能直接解决。但微信小程序似乎更复杂,因为它的渲染方式和网页不太一样,而且涉及到第三方界面的数据,底部标签栏和标题栏。
开发过小程序的同学应该都知道,这些字是直接写在文件里的,不能用动态变量。如果要更改它们,需要使用微信提供的接口方法,稍微复杂一点。
所以如果你需要在微信小程序中切换简繁体,你需要把所有的字符按照简繁体放在一个JS文件中,然后所有的调用都是通过JS进行的。
大约有482个繁体字,所有的字都换成统一的JS。
相关的JS库代码如下:
var arr = { & # 39strPY & # 39='& # 39;的所有对应简化字列表;,'strFT & # 39='所有对应的繁体中文字符列表& # 39;})nbsp;
函数showLag(cc)& nbsp;{
& nbsp& nbspvar & nbspstr & nbsp= & nbsp'';
& nbsp& nbspvar & nbsptemp & nbsp= & nbsp'';
& nbsp& nbsp对于& nbsp(var & nbsp我& nbsp= & nbsp0;& nbsp我& nbsp& lt& nbspcc .长度;& nbspi++){
& nbsp& nbsp& nbsp& nbsptemp & nbsp= & nbspcc.charAt(一);
& nbsp& nbsp& nbsp& nbsp如果& nbsp(cn convert . strpy . index of(temp)& nbsp;!= & nbsp-1){
& nbsp& nbsp& nbsp& nbsp& nbsp& nbspstr & nbsp+= & nbsp;cn convert . strft . charat(cn convert . strpy . index of(temp));
& nbsp& nbsp& nbsp& nbsp}否则{
& nbsp& nbsp& nbsp& nbsp& nbsp& nbspstr & nbsp+= & nbsp;温度;
& nbsp& nbsp& nbsp& nbsp}
& nbsp& nbsp}
& nbsp& nbsp退货& nbsp(str);
}
module . exports . show lag = & nbsp;showLag& nbsp
这段代码类似于网页JS,这里就不详细解释了。很多人问怎么修改标题栏和底部的TAB文字。
可以使用wx . setnavigationbartitle(object object)动态设置当前页面的标题,如下图所示。
下面是动态设置底部选项卡栏中文本的API方法:
& nbsp& nbsp& nbsp& nbsp
界面里的文字呢?这就需要在每次调用接口的时候添加需要的语言参数,然后后台API根据语言参数对结果文本进行转换。
云崛起专注微信小程序定制开发。欢迎有需求的客户咨询我们的生产热线010-57278867。
& nbsp
寒武纪. render(“尾巴”)
本文由“云崛起”原创发布,未经许可,禁止转载!本文原创链接:http://yunjueqi.com/weixinfenxiao/2381.html