UNPKG

automizy-js

Version:

Automizy widget collection

87 lines (85 loc) 2.61 kB
define([ 'automizy/core' ], function () { var i18n = function (obj) { var t = this; t.d = { language: 'en_US', file: '', hasFile: true, logMissing: true, translate: { 'Upload': 'UpLoad' } }; if (typeof obj !== 'undefined') { if (typeof obj.language !== 'undefined') t.language(obj.language); if (typeof obj.file !== 'undefined') t.file(obj.file); if (typeof obj.setTranslate !== 'undefined') t.setTranslate(obj.setTranslate); if (typeof obj.logMissing !== 'undefined') t.logMissing(obj.logMissing); } }; p = i18n.prototype; p.language = function (lang) { var t = this; if (typeof lang === 'string') { t.d.language = lang; return t; } return t.d.language; }; p.file = function (file) { var t = this; if (typeof file === 'string') { t.d.file = file; $.getScript(file).done(function (script, textStatus) { console.log('Automizy.i18n database rebuilt'); }).fail(function (jqxhr, settings, exception) { console.warn('Automizy.i18n database rebuilding failed: ', exception); }); return t; } return t.d.file; }; p.setTranslate = function (obj) { var t = this; if (typeof obj !== 'undefined') { t.d.translate = obj; } return t; }; p.translate = function (text) { var t = this; if (typeof t.d.translate[text] === 'undefined') { if (t.d.logMissing) { console.warn('Missing translate: "' + text + '"'); } } else { var text = t.d.translate[text]; } for (var i = 1; i < arguments.length; i++) { text = text.replace("%s", arguments[i]); } return text; }; p.logMissing = function (b) { var t = this; if (b === true) { t.d.logMissing = b; } else { t.d.logMissing = false; } }; $A.m.i18n = i18n; $A.d.i18n = new $A.m.i18n(); $A.translate = function(){ return $A.d.i18n.translate.apply($A.d.i18n, arguments); }; $A.setTranslate = function(){ return $A.d.i18n.setTranslate.apply($A.d.i18n, arguments); }; });