halo-theme-sakura/script/i18n.min.js

1 line
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";var I18N=function(){var _doc,_i18nlanguage,LOG_TAG="I18N";var _load=function _load(){if(!window.$){Util.loadJS(Poi.themeBase+"/source/js/lib.js",_load)}else if(!window.$.i18n){Util.loadJS(Poi.themeBase+"/source/lib/jquery-i18n/jquery.i18n.min.js",_load)}else if(!window.jsyaml){Util.loadJS(Poi.themeBase+"/source/lib/js-yaml/dist/js-yaml.min.js",_load)}else{_execI18n()}};var _renderI18n=function _renderI18n(){if(!$.i18n){Log.e("未能加载国际化插件,终止国际化操作!",LOG_TAG)}$.i18n.unload();$.i18n.load(_doc);$(".i18n").each(function(){var args=[];var name=$(this).data("iname");var value=$(this).data("ivalue")+"";var attr=$(this).data("iattr");args.push(name);if(value){value=value.split(";");args=args.concat(value)}var text=$.i18n._.apply($.i18n,args);if(attr){$(this).attr(attr,text)}else{$(this).text(text)}})};var _execI18n=function _execI18n(){if(Util.getLocalStorage(_i18nlanguage+".yml")){_doc=JSON.parse(Util.getLocalStorage(_i18nlanguage+".yml"));_renderI18n()}else{$.ajax({url:Poi.themeBase+"/languages/"+_i18nlanguage+".yml",success:function success(data){_doc=jsyaml.safeLoad(data,"utf8");if(!_doc){Log.w("读取读取国际化数据失败",LOG_TAG);return}Util.setLocalStorage(_i18nlanguage+".yml",JSON.stringify(_doc),60*60*24);_renderI18n()}})}};return{init:function init(){if(Poi.i18n&&Poi.i18n!="auto"){_i18nlanguage=Poi.i18n}else if(Util.getLocalStorage("_i18nlanguage")){_i18nlanguage=Util.getLocalStorage("_i18nlanguage")}else{_i18nlanguage=Util.getNavLangSub();Util.setLocalStorage("_i18nlanguage",_i18nlanguage,60*60*24*30)}if(!_i18nlanguage){_i18nlanguage="zh";Log.w("未能判断语言将使用默认语言zh",LOG_TAG)}_load()}}}();