Browse Source

Remove {{ and }} from strings without translation

pull/188/head
Jānis Skarnelis 3 years ago
parent
commit
3002a98e49
  1. 14
      src/shared/Base/Base.js

14
src/shared/Base/Base.js

@ -52,18 +52,18 @@ export class Base {
* @returns {String} * @returns {String}
*/ */
localize(str, params = []) { localize(str, params = []) {
return String(str).replace(/\{\{(\w+).?(\w+)?\}\}/g, (match, key, subkey) => { str = String(str).replace(/\{\{(\w+).?(\w+)?\}\}/g, (match, key, subkey) => {
let rez = false; let rez = "";
// Plugins have `Plugin.l10n.KEY` // Plugins have `Plugin.l10n.KEY`
if (subkey) { if (subkey) {
rez = this.option(`${key[0] + key.toLowerCase().substring(1)}.l10n.${subkey}`); rez = this.option(`${key[0] + key.toLowerCase().substring(1)}.l10n.${subkey}`);
} else { } else if (key) {
rez = this.option(`l10n.${key}`); rez = this.option(`l10n.${key}`);
} }
if (!rez) { if (!rez) {
return key; rez = match;
} }
for (let index = 0; index < params.length; index++) { for (let index = 0; index < params.length; index++) {
@ -72,6 +72,12 @@ export class Base {
return rez; return rez;
}); });
str = str.replace(/\{\{(.*)\}\}/, (match, key) => {
return key;
});
return str;
} }
/** /**

Loading…
Cancel
Save