need loadTranslation to be repeated as dynamic import behaves differently in build mode (vs src mode)

This commit is contained in:
JFH
2021-05-16 00:48:06 +02:00
parent aa50c30610
commit 81a31c3dad
5 changed files with 64 additions and 27 deletions

View File

@@ -8,9 +8,22 @@
*
*/
import { loadExtensionTranslation } from "../../locale.js";
const name = "polystar";
const name = "polystar";
const loadExtensionTranslation = async function (svgEditor) {
let translationModule;
const lang = svgEditor.configObj.pref('lang');
try {
// eslint-disable-next-line no-unsanitized/method
translationModule = await import(`./locale/${lang}.js`);
} catch (_error) {
// eslint-disable-next-line no-console
console.warn(`Missing translation (${lang}) for ${name} - using 'en'`);
// eslint-disable-next-line no-unsanitized/method
translationModule = await import(`./locale/en.js`);
}
svgEditor.i18next.addResourceBundle(lang, name, translationModule.default);
};
export default {
name,
@@ -21,7 +34,7 @@ export default {
let selElems;
let started;
let newFO;
await loadExtensionTranslation(svgEditor, name);
await loadExtensionTranslation(svgEditor);
/**
* @param {boolean} on true=display