From 9ca774aea9ff0d640b127150f3ab21283498bfe7 Mon Sep 17 00:00:00 2001 From: Agriya Dev5 Date: Wed, 19 May 2021 10:43:55 +0530 Subject: [PATCH] #98 extension i18n translate changes --- .../extensions/ext-shapes/ext-shapes.js | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/editor/extensions/ext-shapes/ext-shapes.js b/src/editor/extensions/ext-shapes/ext-shapes.js index 080f1bec..71c7a90a 100644 --- a/src/editor/extensions/ext-shapes/ext-shapes.js +++ b/src/editor/extensions/ext-shapes/ext-shapes.js @@ -6,15 +6,32 @@ * @copyright 2010 Christian Tzurcanu, 2010 Alexis Deveria * */ +const name = "shapes"; + +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: 'shapes', - init () { + name, + async init () { const svgEditor = this; const canv = svgEditor.svgCanvas; const { $id } = canv; const svgroot = canv.getRootElem(); let lastBBox = {}; + await loadExtensionTranslation(svgEditor); const modeId = 'shapelib'; const startClientPos = {}; @@ -27,8 +44,9 @@ export default { callback () { if ($id('tool_shapelib') === null) { const buttonTemplate = document.createElement("template"); + // eslint-disable-next-line no-unsanitized/property buttonTemplate.innerHTML = ` - `; $id('tools_left').append(buttonTemplate.content.cloneNode(true));