2019-12-07 16:58:52 +05:30
|
|
|
// @ts-nocheck
|
2019-11-27 13:39:51 +05:30
|
|
|
function transform(src, modulePath, rootContext) {
|
2019-11-27 14:33:32 +05:30
|
|
|
const json = JSON.parse(src);
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
const moduleId = modulePath
|
|
|
|
.replace(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, '')
|
2019-12-28 16:43:11 +05:30
|
|
|
.replace('packages/app/', '')
|
2019-11-27 14:33:32 +05:30
|
|
|
.replace(/^\/|\/$/g, '')
|
|
|
|
.replace(/\//g, '.');
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return JSON.stringify(
|
|
|
|
Object.keys(json).reduce(
|
|
|
|
(translations, key) => ({
|
|
|
|
...translations,
|
|
|
|
[key]: {
|
|
|
|
id: `${moduleId}.${key}`,
|
|
|
|
defaultMessage: json[key],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
);
|
2019-11-27 13:39:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(content) {
|
2019-11-27 14:33:32 +05:30
|
|
|
this.cacheable && this.cacheable();
|
2019-11-27 13:39:51 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
content = transform(content, this.context, this.rootContext);
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2019-11-27 14:33:32 +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;
|