Remove all *.intl.json files. Move strings to the corresponding views. Implement custom command to build i18n/en.json file

This commit is contained in:
ErickSkrauch
2020-06-04 19:41:27 +03:00
parent 57cf6b3776
commit bf6a76d006
107 changed files with 1122 additions and 972 deletions

View File

@@ -1,38 +0,0 @@
// @ts-nocheck
function transform(src, modulePath, rootContext) {
const json = JSON.parse(src);
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, '')
.replace('packages/app/', '')
.replace(/^\/|\/$/g, '')
.replace(/\//g, '.');
return JSON.stringify(
Object.keys(json).reduce(
(translations, key) => ({
...translations,
[key]: {
id: `${moduleId}.${key}`,
defaultMessage: json[key],
},
}),
{},
),
);
}
module.exports = function (content) {
this.cacheable && this.cacheable();
content = transform(content, this.context, this.rootContext);
return `import { defineMessages } from 'react-intl';
export default defineMessages(${content})`;
};
module.exports.transform = transform;