Skip to content
Snippets Groups Projects
Commit a16dffbd authored by syuilo's avatar syuilo
Browse files

wip

parent 554570cb
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ export default class Replacer { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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);
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment