2017-08-01 23:01:47 +05:30
|
|
|
module.exports = function(content) {
|
2016-05-09 00:58:51 +05:30
|
|
|
this.cacheable && this.cacheable();
|
2017-08-01 23:01:47 +05:30
|
|
|
content = JSON.parse(content);
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2017-08-01 23:01:47 +05:30
|
|
|
const moduleId = this.context
|
2019-07-01 09:09:59 +05:30
|
|
|
.replace(this.rootContext, '')
|
|
|
|
// TODO: can't find the way to strip out this path part programmatically
|
|
|
|
// this is a directory from resolve.modules config
|
|
|
|
// may be this may work: .replace(this._compiler.options.resolve.root, '')
|
|
|
|
.replace('src/', '')
|
2016-05-09 00:58:51 +05:30
|
|
|
.replace(/^\/|\/$/g, '')
|
|
|
|
.replace(/\//g, '.');
|
|
|
|
|
2019-07-01 09:09:59 +05:30
|
|
|
content = JSON.stringify(
|
|
|
|
Object.keys(content).reduce(
|
|
|
|
(translations, key) => ({
|
|
|
|
...translations,
|
|
|
|
[key]: {
|
|
|
|
id: `${moduleId}.${key}`,
|
|
|
|
defaultMessage: content[key]
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
);
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2019-07-01 09:09:59 +05:30
|
|
|
return `import { defineMessages } from 'react-intl';
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2019-07-01 09:09:59 +05:30
|
|
|
export default defineMessages(${content})`;
|
2016-05-09 00:58:51 +05:30
|
|
|
};
|