- String.prototype.tran = function() {
- let s1,s2;
- if (zh_choose === 't') {
- s1 = zh_s;s2 = zh_t;
- }else if(zh_choose === 's') {
- s1 = zh_t;s2 = zh_s;
- }else {
- return this;
- }
- let a = '',l = this.length;
- for(let i=0;i<this.length;i++){
- let c = this.charAt(i),p = s1.indexOf(c)
- a += p < 0 ? c : s2.charAt(p);
- }
- return a;
- }
- function zh_tranBody(obj) {
- let o = (typeof(obj) == "object") ? obj.childNodes : document.body.childNodes;
- for (let i = 0; i < o.length; i++) {
- let c = o.item(i);
- if ('||BR|HR|TEXTAREA|SCRIPT|'.indexOf("|"+c.tagName+"|") > 0) continue;
- if (c.title != '' && c.title != null) c.title = c.title.tran();
- if (c.alt != '' && c.alt != null) c.alt = c.alt.tran();
- if (c.tagName == "INPUT" && c.value != '' && c.type != 'text' && c.type != 'hidden' && c.type != 'password') c.value = c.value.tran();
- if (c.nodeType == 3) {
- c.data = c.data.tran();
- }else{
- zh_tranBody(c);
- }
- }
- }
- //用户设置
- function zh_tran(o) {
- if (o){
- zh_choose = o;
- window.localStorage.setItem('zh_choose',zh_choose);
- }
- if(zh_default !== zh_choose){
- zh_tranBody();
- }
- }
- //初始化
- function zh_init() {
- let get_lang = window.localStorage.getItem('zh_choose'),zh_browserLang = "";
- if (get_lang) {
- zh_choose = get_lang;
- }
- if (zh_choose !== zh_default) {
- if (window.onload) {
- window.onload_before_zh_init = window.onload;
- window.onload = function() {
- zh_tranBody();
- window.onload_before_zh_init();
- };
- }else {
- window.onload = function() {
- zh_tranBody();
- };
- }
- }
- }
- zh_init();
复制代码
|