#98 extension i18n translate changes

master
Agriya Dev5 2021-05-19 10:43:55 +05:30
parent 26113064db
commit 9ca774aea9
1 changed files with 21 additions and 3 deletions

View File

@ -6,15 +6,32 @@
* @copyright 2010 Christian Tzurcanu, 2010 Alexis Deveria * @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 { export default {
name: 'shapes', name,
init () { async init () {
const svgEditor = this; const svgEditor = this;
const canv = svgEditor.svgCanvas; const canv = svgEditor.svgCanvas;
const { $id } = canv; const { $id } = canv;
const svgroot = canv.getRootElem(); const svgroot = canv.getRootElem();
let lastBBox = {}; let lastBBox = {};
await loadExtensionTranslation(svgEditor);
const modeId = 'shapelib'; const modeId = 'shapelib';
const startClientPos = {}; const startClientPos = {};
@ -27,8 +44,9 @@ export default {
callback () { callback () {
if ($id('tool_shapelib') === null) { if ($id('tool_shapelib') === null) {
const buttonTemplate = document.createElement("template"); const buttonTemplate = document.createElement("template");
// eslint-disable-next-line no-unsanitized/property
buttonTemplate.innerHTML = ` buttonTemplate.innerHTML = `
<se-explorerbutton id="tool_shapelib" title="Shape library" lib="./extensions/ext-shapes/shapelib/" <se-explorerbutton id="tool_shapelib" title="${svgEditor.i18next.t(`${name}:buttons.0.title`)}" lib="./extensions/ext-shapes/shapelib/"
src="./images/shapelib.svg"></se-explorerbutton> src="./images/shapelib.svg"></se-explorerbutton>
`; `;
$id('tools_left').append(buttonTemplate.content.cloneNode(true)); $id('tools_left').append(buttonTemplate.content.cloneNode(true));