This commit is contained in:
syuilo 2018-04-15 01:20:46 +09:00
parent 554570cb09
commit a16dffbd75

View File

@ -16,7 +16,7 @@ export default class Replacer {
this.replacement = this.replacement.bind(this); this.replacement = this.replacement.bind(this);
} }
private get(key: string) { private get(path: string, key: string) {
const texts = locale[this.lang]; const texts = locale[this.lang];
if (texts == null) { if (texts == null) {
@ -26,6 +26,15 @@ export default class Replacer {
let text = texts; 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 // Check the key existance
const error = key.split('.').some(k => { const error = key.split('.').some(k => {
if (text.hasOwnProperty(k)) { if (text.hasOwnProperty(k)) {
@ -37,7 +46,7 @@ export default class Replacer {
}); });
if (error) { 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 return key; // Fallback
} else { } else {
return text; return text;
@ -51,18 +60,17 @@ export default class Replacer {
let key = a || b || c; let key = a || b || c;
if (key[0] == '@') { if (key[0] == '@') {
const prefix = name.split('.')[0].replace(/\//g, '.') + '.';
//if (name.startsWith('app/desktop/views/')) prefix = 'desktop.views.'; //if (name.startsWith('app/desktop/views/')) prefix = 'desktop.views.';
//if (name.startsWith('app/mobile/views/')) prefix = 'mobile.views.'; //if (name.startsWith('app/mobile/views/')) prefix = 'mobile.views.';
key = prefix + key.substr(1); key = key.substr(1);
} }
if (match[0] == '"') { if (match[0] == '"') {
return '"' + this.get(key).replace(/"/g, '\\"') + '"'; return '"' + this.get(name, key).replace(/"/g, '\\"') + '"';
} else if (match[0] == "'") { } else if (match[0] == "'") {
return '\'' + this.get(key).replace(/'/g, '\\\'') + '\''; return '\'' + this.get(name, key).replace(/'/g, '\\\'') + '\'';
} else { } else {
return this.get(key); return this.get(name, key);
} }
} }
} }