2019-11-27 13:39:51 +05:30
|
|
|
function transform(src, modulePath, rootContext) {
|
|
|
|
const json = JSON.parse(src);
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2019-11-27 13:39:51 +05:30
|
|
|
const moduleId = modulePath
|
|
|
|
.replace(rootContext, '')
|
2019-07-01 09:09:59 +05:30
|
|
|
// 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-11-27 13:39:51 +05:30
|
|
|
return JSON.stringify(
|
|
|
|
Object.keys(json).reduce(
|
2019-07-01 09:09:59 +05:30
|
|
|
(translations, key) => ({
|
|
|
|
...translations,
|
|
|
|
[key]: {
|
|
|
|
id: `${moduleId}.${key}`,
|
2019-11-27 13:39:51 +05:30
|
|
|
defaultMessage: json[key]
|
2019-07-01 09:09:59 +05:30
|
|
|
}
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
);
|
2019-11-27 13:39:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(content) {
|
|
|
|
this.cacheable && this.cacheable();
|
|
|
|
|
|
|
|
content = transform(content, this.context, this.rootContext);
|
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
|
|
|
};
|
2019-11-27 13:39:51 +05:30
|
|
|
|
|
|
|
module.exports.transform = transform;
|