This commit is contained in:
syuilo
2017-03-26 03:23:19 +09:00
parent b2587a192a
commit 7dd709f8a6
8 changed files with 141 additions and 38 deletions

View File

@ -33,7 +33,23 @@ module.exports = (Object as any).entries(languages).map(([lang, locale]) => {
exclude: /node_modules/,
loader: StringReplacePlugin.replace({
replacements: [
{ pattern: /%i18n:(.+?)%/g, replacement: (_, text) => eval('locale' + text.split('.').map(x => `['${x}']`).join('')) }
{ pattern: /%i18n:(.+?)%/g, replacement: (_, key) => {
let text = locale;
const error = key.split('.').some(k => {
if (text.hasOwnProperty(k)) {
text = text[k];
return false;
} else {
return true;
}
});
if (error) {
console.warn(`key '${key}' not found in '${lang}'`);
return '-UNTRANSLATED-';
} else {
return text.replace(/'/g, '\\\'').replace(/"/g, '\\"');
}
} }
]
})
},