var lang = {},
    /** @type {Object!} */
    locale,
    /** @type {Array<Function>} */
    onLangInitialized = [];

/**
 * @param {string=} lg
**/
function initLang(lg) {
    if (!lg) {
        for (var i=0, nbLang = navigator.languages.length; i < nbLang; i++)
            if (lang.hasOwnProperty(navigator.languages[i])) {
                lg = navigator.languages[i];
                break;
            }
        if (!lg)
            lg = 'en';
    }
    locale = lang[lg];
    console.log("Loading language pack: " +lg);
    if (locale.dom)
        for (var domId in locale.dom) {
            var dom = document.getElementById(domId);
            if (dom)
                dom.textContent = locale.dom[domId];
        }
    onLangInitialized.forEach(function(fnc) {
        fnc();
    });
}

