なんかもうめっちゃ変えた

This commit is contained in:
syuilo
2017-12-17 14:35:30 +09:00
parent 5c36423841
commit d4fb399c95
21 changed files with 185 additions and 118 deletions

View File

@ -3,28 +3,10 @@
*/
const StringReplacePlugin = require('string-replace-webpack-plugin');
import Replacer from '../../../src/common/build/i18n';
export default (lang, locale) => {
function get(key: string) {
let text = locale;
// Check the key existance
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 key; // Fallback
} else {
return text;
}
}
export default lang => {
const replacer = new Replacer(lang);
return {
enforce: 'pre',
@ -32,14 +14,7 @@ export default (lang, locale) => {
exclude: /node_modules/,
loader: StringReplacePlugin.replace({
replacements: [{
pattern: /"%i18n:(.+?)%"/g, replacement: (_, key) =>
'"' + get(key).replace(/"/g, '\\"') + '"'
}, {
pattern: /'%i18n:(.+?)%'/g, replacement: (_, key) =>
'\'' + get(key).replace(/'/g, '\\\'') + '\''
}, {
pattern: /%i18n:(.+?)%/g, replacement: (_, key) =>
get(key)
pattern: replacer.pattern, replacement: replacer.replacement
}]
})
};