2020-02-13 11:14:47 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
|
|
const {
|
|
|
|
createSingleMessagesFile,
|
|
|
|
default: manageTranslations
|
|
|
|
} = require("react-intl-translations-manager");
|
|
|
|
|
2020-02-13 11:58:45 +00:00
|
|
|
const dotSeparator = "_dot_";
|
2020-02-13 11:14:47 +00:00
|
|
|
const sortKeys = true;
|
|
|
|
const translationsDirectory = "locale";
|
|
|
|
|
|
|
|
manageTranslations({
|
|
|
|
messagesDirectory: "build/locale/src",
|
|
|
|
overrideCoreMethods: {
|
|
|
|
outputSingleFile: combinedFiles => {
|
|
|
|
const msgDescriptors = combinedFiles.reduce(
|
|
|
|
(acc, messages) => [...acc, ...messages.descriptors],
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
const structuredJsonFormat = msgDescriptors.reduce((msgs, msg) => {
|
2020-02-13 11:50:39 +00:00
|
|
|
const key = msg.id.replace(/\./g, dotSeparator);
|
2020-02-13 11:14:47 +00:00
|
|
|
if (msgs[key] && msgs[key].context === undefined) {
|
|
|
|
msgs[key].context = msg.description;
|
|
|
|
} else {
|
|
|
|
msgs[key] = {
|
|
|
|
context: msg.description,
|
|
|
|
string: msg.defaultMessage
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
createSingleMessagesFile({
|
|
|
|
directory: translationsDirectory,
|
|
|
|
messages: structuredJsonFormat,
|
|
|
|
sortKeys
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
singleMessagesFile: true,
|
|
|
|
sortKeys,
|
|
|
|
translationsDirectory
|
|
|
|
});
|