diff --git a/src/config.js b/src/config.js index d035d48..65c91d7 100644 --- a/src/config.js +++ b/src/config.js @@ -3,13 +3,15 @@ import i18n from './i18n'; const defaultLangCode = 'en'; const getProp = (langCode, prop) => { - if (i18n[langCode]) { + if (i18n[langCode] && i18n[langCode][prop]) { return i18n[langCode][prop]; } + const code = langCode.split('-')[0]; - if (i18n[code]) { + if (i18n[code] && i18n[code][prop]) { return i18n[code][prop]; } + return i18n[defaultLangCode][prop]; }; @@ -19,4 +21,6 @@ export const Config = { getProp(langCode, 'tooltipText1'), tooltipText2: (langCode = defaultLangCode) => getProp(langCode, 'tooltipText2'), + distanceAndLength: (langCode = defaultLangCode) => + getProp(langCode, 'distanceAndLength'), }; diff --git a/src/i18n.js b/src/i18n.js index 0d8fcef..3ae9c5d 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -2,6 +2,7 @@ const i18n = { en: { tooltipText1: 'Drag to change, click to remove', tooltipText2: 'Drag to change', + distanceAndLength: (lenght, area) => `Total distance: ${lenght}; Total area: ${area}.` }, it: { tooltipText1: 'Trascina per modificare, fai clic per rimuovere', @@ -26,6 +27,7 @@ const i18n = { pt: { tooltipText1: 'Arraste para alterar, clique para remover', tooltipText2: 'Arraste para alterar', + distanceAndLength: (lenght, area) => `Distância total: ${lenght}; Área total: ${area}.` }, uk: { tooltipText1: 'Перетягніть, щоб змінити, натисніть, щоб видалити', diff --git a/src/index.js b/src/index.js index 1ff50a2..17dfc52 100644 --- a/src/index.js +++ b/src/index.js @@ -1024,7 +1024,7 @@ export default class MeasureTool { this._nodeText .select(':last-child') .text( - `Total distance: ${this.lengthText}; Total area: ${this.areaText}.` + Config.distanceAndLength(this._options.language)(this.lengthText, this.areaText) ); } }