import { addSupportedLanguage, loadMessages } from '@kano/i18n/dist/index.js';
import * as path from '../util/path.js';
import { blocklyLangMap } from './blockly.js';
export * from '@kano/i18n/dist/index.js';
export * from '@kano/i18n/dist/polymer.js';
const DEFAULT_MODULES_PATH = '/node_modules/';
addSupportedLanguage('es-AR');
addSupportedLanguage('fr-FR');
function addBlocklyMsg(m) {
    if ('Blockly' in window) {
        Object.assign(window.Blockly.Msg, m);
    }
    else {
        window.CustomBlocklyMsg = window.CustomBlocklyMsg || {};
        Object.assign(window.CustomBlocklyMsg, m);
    }
}
export function loadBlocklyMsg(url) {
    return loadMessages(url)
        .then((m) => {
        addBlocklyMsg(m);
        return m;
    });
}
export function load(lang, opts = { modulesPath: DEFAULT_MODULES_PATH }) {
    const modulesPath = opts.modulesPath || DEFAULT_MODULES_PATH;
    const kanoCodePath = opts.kanoCodePath || path.join(modulesPath, '/@kano/code');
    const tasks = [loadMessages(path.join(kanoCodePath, `/locale/editor/${lang}.json`))];
    if (opts.blockly) {
        tasks.push(loadBlocklyMsg(path.join(kanoCodePath, `/locale/blockly/${lang}.json`)));
        tasks.push(loadBlocklyMsg(path.join(modulesPath, `/@kano/kwc-blockly/blockly_built/msg/json/${blocklyLangMap[lang]}.json`)));
        tasks.push(loadBlocklyMsg(path.join(modulesPath, '/@kano/kwc-blockly/blockly_built/msg/json/constants.json')));
    }
    return Promise.all(tasks);
}
export default {
    load,
    loadBlocklyMsg,
};
//# sourceMappingURL=index.js.map