/* * @Author: printempw * @Date: 2016-07-16 09:02:32 * @Last Modified by: printempw * @Last Modified time: 2016-09-26 22:35:35 */ $.locales = {}; var locale = {}; /** * Check if given value is empty. * * @param {any} obj * @return {Boolean} */ function isEmpty(obj) { // null and undefined are "empty" if (obj == null) return true; // Assume if it has a length property with a non-zero value // that that property is correct. if (obj.length > 0) return false; if (obj.length === 0) return true; // If it isn't an object at this point // it is empty, but it can't be anything *but* empty // Is it empty? Depends on your application. if (typeof obj !== "object") return true; // Otherwise, does it have any properties of its own? // Note that this doesn't handle // toString and valueOf enumeration bugs in IE < 9 for (var key in obj) { if (hasOwnProperty.call(obj, key)) return false; } return true; } /** * Load current selected language. * * @return void */ function loadLocales() { for (lang in $.locales) { if (!isEmpty($.locales[lang])) { locale = $.locales[lang] || {}; } } } /** * Translate according to given key. * * @param {string} key * @param {dict} parameters * @return {string} */ function trans(key, parameters) { if (isEmpty(locale)) { loadLocales(); } parameters = parameters || {}; var segments = key.split('.'); var temp = locale || {}; for (i in segments) { if (isEmpty(temp[segments[i]])) { return key; } else { temp = temp[segments[i]]; } } for (i in parameters) { if (!isEmpty(parameters[i])) { temp = temp.replace(':'+i, parameters[i]); } } return temp; } function showModal(msg, title, type, callback) { title = title === undefined ? "Messgae" : title; type = type === undefined ? "default" : type; callback = callback === undefined ? 'data-dismiss="modal"' : 'onclick="'+callback+'"'; var btn_type = (type != "default") ? "btn-outline" : "btn-primary"; var dom = '