Can babel-plugin-react-intl export multiple translations to multiple files on path -> one file
ieugen opened this issue · 1 comments
Which package?
babel-plugin-react-intl
Is your feature request related to a problem? Please describe.
I have a set of components (reports) (kind of like a mono-repo - but in a single create react app).
I want to export the translations for each report (directory path) into it's own translations file.
I do not want translations texts from a report (set of react components) to be in the same file as texts from another report.
Describe the solution you'd like
The ability to configure the plugin to run multiple times, one per path and do it's thing.
Describe alternatives you've considered
Splitting the project into multiple packages - not ok. Having multiple configurations ?!
src/reports
├── report-1
├── report-2
I managed to do it by calling the node API for https://github.com/GertjanReynaert/react-intl-translations-manager .
const reports = ['reports/report-1', 'reports/report-2' ];
function extractTextsFromReport(reportPath) {
console.log(`Resolving ${reportPath}`);
return manageTranslations({
messagesDirectory: `build/messages/src/main/js/${reportPath}`,
translationsDirectory: `src/translations/${reportPath}`,
singleMessagesFile: true,
sortKeys: true,
languages: ['en'],
});
}
function exportTranslations() {
const promisses = reports.map((translation) => extractTextsFromReport(translation));
return Promise.resolve('the value is ignored. keep to signal async completion.');
}