🌐(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:
104
src/frontend/packages/i18n/__tests__/i18n.test.ts
Normal file
104
src/frontend/packages/i18n/__tests__/i18n.test.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
describe('integration testing on i18n package', () => {
|
||||
afterAll(() => {
|
||||
fs.rmSync('./locales/tests', { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('cmd extract-translation:impress', () => {
|
||||
// To be sure the file is not here
|
||||
fs.rmSync('./locales/impress/translations-crowdin.json', {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
expect(
|
||||
fs.existsSync('./locales/impress/translations-crowdin.json'),
|
||||
).toBeFalsy();
|
||||
|
||||
// Generate the file
|
||||
execSync('yarn extract-translation:impress');
|
||||
expect(
|
||||
fs.existsSync('./locales/impress/translations-crowdin.json'),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('cmd format-deploy', () => {
|
||||
// To be sure the tests folder is not here
|
||||
fs.rmSync('./locales/tests', { recursive: true, force: true });
|
||||
expect(fs.existsSync('./locales/tests')).toBeFalsy();
|
||||
|
||||
// Generate english json file
|
||||
fs.mkdirSync('./locales/tests/en/', { recursive: true });
|
||||
fs.writeFileSync(
|
||||
'./locales/tests/en/translations.json',
|
||||
JSON.stringify({ test: { message: 'My test' } }),
|
||||
'utf8',
|
||||
);
|
||||
expect(fs.existsSync('./locales/tests/en/translations.json')).toBeTruthy();
|
||||
|
||||
fs.mkdirSync('./locales/tests/fr/', { recursive: true });
|
||||
fs.writeFileSync(
|
||||
'./locales/tests/fr/translations.json',
|
||||
JSON.stringify({ test: { message: 'Mon test' } }),
|
||||
'utf8',
|
||||
);
|
||||
expect(fs.existsSync('./locales/tests/fr/translations.json')).toBeTruthy();
|
||||
|
||||
// Execute format-deploy command
|
||||
const output = './locales/tests/translations.json';
|
||||
execSync(`node ./format-deploy.mjs --app=tests --output=${output}`);
|
||||
const json = JSON.parse(fs.readFileSync(output, 'utf8'));
|
||||
expect(json).toEqual({
|
||||
en: {
|
||||
translation: { test: 'My test' },
|
||||
},
|
||||
fr: {
|
||||
translation: { test: 'Mon test' },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('cmd format-deploy throws an error when translation file is not found', () => {
|
||||
// To be sure the tests folder is not here
|
||||
fs.rmSync('./locales/tests', { recursive: true, force: true });
|
||||
expect(fs.existsSync('./locales/tests')).toBeFalsy();
|
||||
|
||||
// Generate english json file
|
||||
fs.mkdirSync('./locales/tests/en/', { recursive: true });
|
||||
|
||||
// Execute format-deploy command
|
||||
const output = './locales/tests/translations.json';
|
||||
|
||||
const cmd = () => {
|
||||
execSync(`node ./format-deploy.mjs --app=tests --output=${output}`, {
|
||||
stdio: 'pipe',
|
||||
});
|
||||
};
|
||||
|
||||
expect(cmd).toThrow(
|
||||
`Error: File locales${path.sep}tests${path.sep}en${path.sep}translations.json not found!`,
|
||||
);
|
||||
});
|
||||
|
||||
test('cmd format-deploy throws an error when no translation to deploy', () => {
|
||||
// To be sure the tests folder is not here
|
||||
fs.rmSync('./locales/tests', { recursive: true, force: true });
|
||||
expect(fs.existsSync('./locales/tests')).toBeFalsy();
|
||||
|
||||
// Generate english json file
|
||||
fs.mkdirSync('./locales/tests/', { recursive: true });
|
||||
|
||||
// Execute format-deploy command
|
||||
const output = './locales/tests/translations.json';
|
||||
|
||||
const cmd = () => {
|
||||
execSync(`node ./format-deploy.mjs --app=tests --output=${output}`, {
|
||||
stdio: 'pipe',
|
||||
});
|
||||
};
|
||||
|
||||
expect(cmd).toThrow('Error: No translation to deploy');
|
||||
});
|
||||
});
|
||||
47
src/frontend/packages/i18n/__tests__/translations.test.ts
Normal file
47
src/frontend/packages/i18n/__tests__/translations.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user