From 9fc4ccca361882944815f725228e5e8414a65426 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 15 Apr 2018 01:20:46 +0900 Subject: [PATCH] wip --- src/build/i18n.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/build/i18n.ts b/src/build/i18n.ts index d9dacccd3..1fb43a13c 100644 --- a/src/build/i18n.ts +++ b/src/build/i18n.ts @@ -16,7 +16,7 @@ export default class Replacer { this.replacement = this.replacement.bind(this); } - private get(key: string) { + private get(path: string, key: string) { const texts = locale[this.lang]; if (texts == null) { @@ -26,6 +26,15 @@ export default class Replacer { let text = texts; + if (path) { + if (text.hasOwnProperty(path)) { + text = text[path]; + } else { + console.warn(`path '${path}' not found in '${this.lang}'`); + return key; // Fallback + } + } + // Check the key existance const error = key.split('.').some(k => { if (text.hasOwnProperty(k)) { @@ -37,7 +46,7 @@ export default class Replacer { }); if (error) { - console.warn(`key '${key}' not found in '${this.lang}'`); + console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`); return key; // Fallback } else { return text; @@ -51,18 +60,17 @@ export default class Replacer { let key = a || b || c; if (key[0] == '@') { - const prefix = name.split('.')[0].replace(/\//g, '.') + '.'; //if (name.startsWith('app/desktop/views/')) prefix = 'desktop.views.'; //if (name.startsWith('app/mobile/views/')) prefix = 'mobile.views.'; - key = prefix + key.substr(1); + key = key.substr(1); } if (match[0] == '"') { - return '"' + this.get(key).replace(/"/g, '\\"') + '"'; + return '"' + this.get(name, key).replace(/"/g, '\\"') + '"'; } else if (match[0] == "'") { - return '\'' + this.get(key).replace(/'/g, '\\\'') + '\''; + return '\'' + this.get(name, key).replace(/'/g, '\\\'') + '\''; } else { - return this.get(key); + return this.get(name, key); } } }