Commit d89c9ebe authored by antoor's avatar antoor

Refactoring language template loading scheme

重构语言模板加载方案
parent fb74243c
//
// 程序入口
// -------
// create: 2015/12/20
// update: 2016/04/02
//
/**
* 中国蚁剑::程序入口
* 创建:2015/12/20
* 更新:2016/04/16
* 作者:蚁逅 <https://github.com/antoor>
*/
'use strict';
......@@ -15,13 +15,32 @@ import Menubar from './base/menubar';
import CacheManager from './base/cachemanager';
const antSword = window.antSword = {
/**
* XSS过滤函数
* @param {String} html 过滤前字符串
* @return {String} 过滤后的字符串
*/
noxss: (html) => {
return String(html).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
},
/**
* 核心模块
* @type {Object}
*/
core: {},
/**
* 操作模块
* @type {Object}
*/
modules: {},
// localStorage存储
// 参数{key:存储键值,[value]:存储内容,[def]:默认内容}
/**
* localStorage存储API
* ? 如果只有一个key参数,则返回内容,否则进行设置
* @param {String} key 存储键值,必选
* @param {String} value 存储内容,可选
* @param {String} def 默认内容,可选
* @return {None} [description]
*/
storage: (key, value, def) => {
// 读取
if (!value) {
......@@ -32,13 +51,11 @@ const antSword = window.antSword = {
}
};
// 加载模板代码
// 加载核心模板
antSword['core'] = require('./core/index');
// 加载显示语言
let _lang = localStorage.getItem('language') || navigator.language;
_lang = ['en', 'zh'].indexOf(_lang) === -1 ? 'en' : _lang;
antSword['language'] = require(`./language/${_lang}`);
// 加载语言模板
antSword['language'] = require('./language/index');
// 加载代理
const aproxy = {
......
/**
* 中国蚁剑::语言模板
*/
'use strict';
// 获取本地设置语言(如若没有,则获取浏览器语言
let lang = antSword['storage']('language',
false,
navigator.language
);
// 判断本地设置语言是否符合语言模板
lang = ['en', 'zh'].indexOf(lang) === -1 ? 'en' : lang;
// 返回语言模板
module.exports = require(`./${lang}`);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment