mirror of
https://github.com/elyby/emails-renderer.git
synced 2024-11-27 01:02:05 +05:30
26 lines
669 B
JavaScript
26 lines
669 B
JavaScript
|
const path = require('path');
|
||
|
|
||
|
module.exports = function(input) {
|
||
|
this.cacheable && this.cacheable();
|
||
|
|
||
|
const moduleId = this.context
|
||
|
.replace(path.join(this.rootContext, 'src'), '')
|
||
|
.replace(/^\/|\/$/g, '')
|
||
|
.replace(/\//g, '.');
|
||
|
|
||
|
const json = JSON.parse(input);
|
||
|
const result = JSON.stringify(Object.keys(json).reduce((translations, key) => {
|
||
|
translations[key] = {
|
||
|
id: `${moduleId}.${key}`,
|
||
|
defaultMessage: json[key],
|
||
|
};
|
||
|
|
||
|
return translations;
|
||
|
}, {}));
|
||
|
|
||
|
return `
|
||
|
import { defineMessages } from 'react-intl';
|
||
|
export default defineMessages(${result})
|
||
|
`;
|
||
|
};
|