/* svn info: $Revision: 1173 $ $Date: 2018-11-13 15:53:42 +0800 (Tue, 13 Nov 2018) $ */
function LOCALIZE() {}
LOCALIZE.prototype = {
    localize: null,
    ajax: null,
    GetLangfile: function (e) {
        var n = this;
        "auto" === e && (e = (navigator.browserLanguage || navigator.language).toLowerCase());
        localStorage.setItem("router-lang", e);
        this.ajax = $.ajax({
            url: "./js/lang/" + e + ".json",
            dataType:'jsonp',
            crossDomain: true,
            jsonpCallback: "JsonP_Lang",
        }).done(function (e) {
            n.localize = e, sessionStorage.setItem("langPack", JSON.stringify(e));
        }).fail(function (e, n, a) {})
    },
    LangReplace: function (a, n) {
        try {
            var e = 0 < a.length ? new RegExp("\\$([1-" + a.length.toString() + "])", "g") : null,
                t = this.localize.hasOwnProperty(n) ? this.localize[n] : n;
            return String(t).replace(e, function (e, n) {
                return a[++n]
            })
        } catch (e) {
            return n
        }
    }
};
var LANG = new LOCALIZE;

function InitLANG(e) {
    if (!sessionStorage.getItem("langPack"))
        LANG.GetLangfile(e);
    else
        LANG.localize = JSON.parse(sessionStorage.getItem("langPack"));
}

function ChangeLANG(e) {
    if (null == localStorage.getItem("router-lang") || localStorage.getItem("router-lang") != e) {
        LANG.GetLangfile(e);
    }
    location.reload();
}

function I18N(e, n, a) {
    var t, o = arguments;
    if (n = n.toString() || "", t = LANG.LangReplace(o, n), null != a && (0 == isNaN(a) ? t = t.replace(/%d/g, a) : t = t.replace(/%s/g, a)), "h" === e) document.write(t);
    else if ("j" === e) return t
}

function I18N_Translate(selector) {
     var e = selector ? $(selector).find(".i18n") : $(".i18n");
     e.each(function (i, e) {
         var n = $(e).attr("data-i18n-name");
         n && (e.tagName !="INPUT"?$(e).text(I18N("j", n)):e.placeholder = I18N("j", n));
    })
}

(function ($) {
    'use strict';
    null == localStorage.getItem("router-lang") ? InitLANG("en-us") : InitLANG(localStorage.getItem("router-lang"));
    $.when(LANG.ajax).done(function () {
        I18N_Translate();
    });
})(jQuery)