From deafb994cf9c838296ba9632921965cd719d3770 Mon Sep 17 00:00:00 2001 From: Agriya Dev5 Date: Tue, 18 May 2021 18:42:29 +0530 Subject: [PATCH] #98 extension connectors i18n translate changes --- .../extensions/ext-connector/ext-connector.js | 24 ++++++++++++------- .../extensions/ext-connector/locale/en.js | 1 + .../extensions/ext-connector/locale/fr.js | 1 + .../extensions/ext-connector/locale/zh-CN.js | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/editor/extensions/ext-connector/ext-connector.js b/src/editor/extensions/ext-connector/ext-connector.js index 93675bdf..de2c7b32 100644 --- a/src/editor/extensions/ext-connector/ext-connector.js +++ b/src/editor/extensions/ext-connector/ext-connector.js @@ -7,21 +7,25 @@ * */ -const loadExtensionTranslation = async function (lang) { +const name = "connector"; + +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/${encodeURIComponent(lang)}.js`); + translationModule = await import(`./locale/${lang}.js`); } catch (_error) { // eslint-disable-next-line no-console - console.error(`Missing translation (${lang}) - using 'en'`); + console.warn(`Missing translation (${lang}) for ${name} - using 'en'`); + // eslint-disable-next-line no-unsanitized/method translationModule = await import(`./locale/en.js`); } - return translationModule.default; + svgEditor.i18next.addResourceBundle(lang, name, translationModule.default); }; export default { - name: 'connector', + name, async init(S) { const svgEditor = this; const { svgCanvas } = svgEditor; @@ -29,6 +33,7 @@ export default { const { $, svgroot } = S, addElem = svgCanvas.addSVGElementFromJson, selManager = S.selectorManager; + await loadExtensionTranslation(svgEditor); let startX; let startY; @@ -349,16 +354,15 @@ export default { }); }; - const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang')); return { /** @todo JFH special flag */ newUI: true, - name: strings.name, + name: svgEditor.i18next.t(`${name}:name`), callback() { // Add the button and its handler(s) const buttonTemplate = document.createElement("template"); buttonTemplate.innerHTML = ` - + `; $id('tools_left').append(buttonTemplate.content.cloneNode(true)); $id('mode_connect').addEventListener("click", () => { @@ -367,7 +371,9 @@ export default { }, /* async */ addLangData({ _lang }) { // , importLocale: importLoc return { - data: strings.langList + data: [ + { id: 'mode_connect', title: svgEditor.i18next.t(`${name}:langListTitle`) } + ] }; }, mouseDown(opts) { diff --git a/src/editor/extensions/ext-connector/locale/en.js b/src/editor/extensions/ext-connector/locale/en.js index f360d7a8..5a9aab4d 100644 --- a/src/editor/extensions/ext-connector/locale/en.js +++ b/src/editor/extensions/ext-connector/locale/en.js @@ -1,5 +1,6 @@ export default { name: 'Connector', + langListTitle: 'Connect two objects', langList: [ { id: 'mode_connect', title: 'Connect two objects' } ], diff --git a/src/editor/extensions/ext-connector/locale/fr.js b/src/editor/extensions/ext-connector/locale/fr.js index f38172c2..3132cdba 100644 --- a/src/editor/extensions/ext-connector/locale/fr.js +++ b/src/editor/extensions/ext-connector/locale/fr.js @@ -1,5 +1,6 @@ export default { name: 'Connector', + langListTitle: 'Connecter deux objets', langList: [ { id: 'mode_connect', title: 'Connecter deux objets' } ], diff --git a/src/editor/extensions/ext-connector/locale/zh-CN.js b/src/editor/extensions/ext-connector/locale/zh-CN.js index 5de0be8c..e3782bbc 100755 --- a/src/editor/extensions/ext-connector/locale/zh-CN.js +++ b/src/editor/extensions/ext-connector/locale/zh-CN.js @@ -1,5 +1,6 @@ export default { name: '连接器', + langListTitle: '连接两个对象', langList: [ { id: 'mode_connect', title: '连接两个对象' } ],