#98 extension connectors i18n translate changes

master
Agriya Dev5 2021-05-18 18:42:29 +05:30
parent 1f800fab38
commit deafb994cf
4 changed files with 18 additions and 9 deletions

View File

@ -7,21 +7,25 @@
* *
*/ */
const loadExtensionTranslation = async function (lang) { const name = "connector";
const loadExtensionTranslation = async function (svgEditor) {
let translationModule; let translationModule;
const lang = svgEditor.configObj.pref('lang');
try { try {
// eslint-disable-next-line no-unsanitized/method // eslint-disable-next-line no-unsanitized/method
translationModule = await import(`./locale/${encodeURIComponent(lang)}.js`); translationModule = await import(`./locale/${lang}.js`);
} catch (_error) { } catch (_error) {
// eslint-disable-next-line no-console // 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`); translationModule = await import(`./locale/en.js`);
} }
return translationModule.default; svgEditor.i18next.addResourceBundle(lang, name, translationModule.default);
}; };
export default { export default {
name: 'connector', name,
async init(S) { async init(S) {
const svgEditor = this; const svgEditor = this;
const { svgCanvas } = svgEditor; const { svgCanvas } = svgEditor;
@ -29,6 +33,7 @@ export default {
const { $, svgroot } = S, const { $, svgroot } = S,
addElem = svgCanvas.addSVGElementFromJson, addElem = svgCanvas.addSVGElementFromJson,
selManager = S.selectorManager; selManager = S.selectorManager;
await loadExtensionTranslation(svgEditor);
let startX; let startX;
let startY; let startY;
@ -349,16 +354,15 @@ export default {
}); });
}; };
const strings = await loadExtensionTranslation(svgEditor.configObj.pref('lang'));
return { return {
/** @todo JFH special flag */ /** @todo JFH special flag */
newUI: true, newUI: true,
name: strings.name, name: svgEditor.i18next.t(`${name}:name`),
callback() { callback() {
// Add the button and its handler(s) // Add the button and its handler(s)
const buttonTemplate = document.createElement("template"); const buttonTemplate = document.createElement("template");
buttonTemplate.innerHTML = ` buttonTemplate.innerHTML = `
<se-button id="mode_connect" title="Connect two objects" src="./images/conn.svg"></se-button> <se-button id="mode_connect" title="${svgEditor.i18next.t(`${name}:langListTitle`)}" src="./images/conn.svg"></se-button>
`; `;
$id('tools_left').append(buttonTemplate.content.cloneNode(true)); $id('tools_left').append(buttonTemplate.content.cloneNode(true));
$id('mode_connect').addEventListener("click", () => { $id('mode_connect').addEventListener("click", () => {
@ -367,7 +371,9 @@ export default {
}, },
/* async */ addLangData({ _lang }) { // , importLocale: importLoc /* async */ addLangData({ _lang }) { // , importLocale: importLoc
return { return {
data: strings.langList data: [
{ id: 'mode_connect', title: svgEditor.i18next.t(`${name}:langListTitle`) }
]
}; };
}, },
mouseDown(opts) { mouseDown(opts) {

View File

@ -1,5 +1,6 @@
export default { export default {
name: 'Connector', name: 'Connector',
langListTitle: 'Connect two objects',
langList: [ langList: [
{ id: 'mode_connect', title: 'Connect two objects' } { id: 'mode_connect', title: 'Connect two objects' }
], ],

View File

@ -1,5 +1,6 @@
export default { export default {
name: 'Connector', name: 'Connector',
langListTitle: 'Connecter deux objets',
langList: [ langList: [
{ id: 'mode_connect', title: 'Connecter deux objets' } { id: 'mode_connect', title: 'Connecter deux objets' }
], ],

View File

@ -1,5 +1,6 @@
export default { export default {
name: '连接器', name: '连接器',
langListTitle: '连接两个对象',
langList: [ langList: [
{ id: 'mode_connect', title: '连接两个对象' } { id: 'mode_connect', title: '连接两个对象' }
], ],