Basic functionality for locale change. Draft implementation of tools for working with i18n

This commit is contained in:
SleepWalker
2016-05-08 22:28:51 +03:00
parent 8db3c36261
commit 4f5f18d787
18 changed files with 491 additions and 108 deletions

21
webpack/intl-loader.js Normal file
View File

@ -0,0 +1,21 @@
module.exports = function() {
this.cacheable && this.cacheable();
var moduleId = this.context
.replace(this.options.resolve.root, '')
.replace(/^\/|\/$/g, '')
.replace(/\//g, '.');
var content = this.inputValue[0];
content = JSON.stringify(Object.keys(content).reduce(function(translations, key) {
translations[key] = {
id: moduleId + '.' + key,
defaultMessage: content[key]
};
return translations;
}, {}));
return 'import { defineMessages } from \'react-intl\';'
+ 'export default defineMessages(' + content + ')';
};