🌐(i18n) create package i18n

The package i18n will handle the
internationalization of the applications.
It will parse the frontend code and extract
the translations to be send to the crowdin
platform.
This commit is contained in:
Anthony LC
2024-04-02 16:19:35 +02:00
committed by Anthony LC
parent 3098b9f4fc
commit dfafd335f4
11 changed files with 297 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import { execSync } from 'child_process';
import fs from 'fs';
describe('checks all the frontend translation are made', () => {
it('checks missing translation. If this test fails, go to https://crowdin.com/', () => {
// Extract the translations
execSync(
'yarn extract-translation:impress -c ./i18next-parser.config.jest.mjs',
);
const outputCrowdin = './locales/impress/translations-crowdin.json';
const jsonCrowdin = JSON.parse(fs.readFileSync(outputCrowdin, 'utf8'));
const listKeysCrowdin = Object.keys(jsonCrowdin).sort();
// Check the translations in the app impress
const outputimpress = '../../apps/impress/src/i18n/translations.json';
const jsonimpress = JSON.parse(fs.readFileSync(outputimpress, 'utf8'));
// Our keys are in english, so we don't need to check the english translation
Object.keys(jsonimpress)
.filter((key) => key !== 'en')
.forEach((key) => {
const listKeysimpress = Object.keys(jsonimpress[key].translation).sort();
const missingKeys = listKeysCrowdin.filter(
(element) => !listKeysimpress.includes(element),
);
const additionalKeys = listKeysimpress.filter(
(element) => !listKeysCrowdin.includes(element),
);
if (missingKeys.length > 0) {
console.log(
`Missing keys in impress translations that should be translated in Crowdin, got to https://crowdin.com/ :`,
missingKeys,
);
}
if (additionalKeys.length > 0) {
console.log(
`Additional keys in impress translations that seems not present in this branch:`,
additionalKeys,
);
}
expect(missingKeys.length).toBe(0);
});
});
});