Update i18n.ts

This commit is contained in:
こぴなたみぽ 2017-05-17 06:22:54 +09:00 committed by GitHub
parent 1a474d13d6
commit 41f7e38547

View File

@ -13,6 +13,8 @@ export default (lang, locale) => ({
{
pattern: /%i18n:(.+?)%/g, replacement: (_, key) => {
let text = locale;
// Check the key existance
const error = key.split('.').some(k => {
if (text.hasOwnProperty(k)) {
text = text[k];
@ -21,9 +23,10 @@ export default (lang, locale) => ({
return true;
}
});
if (error) {
console.warn(`key '${key}' not found in '${lang}'`);
return key;
return key; // Fallback
} else {
return text.replace(/'/g, '\\\'').replace(/"/g, '\\"');
}