2019-03-17 04:07:00 +05:30
|
|
|
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) => {
|
2019-05-10 04:23:28 +05:30
|
|
|
const value = json[key];
|
|
|
|
const id = `${moduleId}.${key}`;
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
translations[key] = {
|
|
|
|
...value,
|
|
|
|
id,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
translations[key] = {
|
|
|
|
id,
|
|
|
|
defaultMessage: value,
|
|
|
|
};
|
|
|
|
}
|
2019-03-17 04:07:00 +05:30
|
|
|
|
|
|
|
return translations;
|
|
|
|
}, {}));
|
|
|
|
|
|
|
|
return `
|
|
|
|
import { defineMessages } from 'react-intl';
|
2019-05-10 04:23:28 +05:30
|
|
|
export default defineMessages(${result});
|
2019-03-17 04:07:00 +05:30
|
|
|
`;
|
|
|
|
};
|