feat: more languages (#10595)

chore: more languages
This commit is contained in:
Jason Rasmussen 2024-06-24 14:15:08 -04:00 committed by GitHub
parent 13cc1f0aa6
commit fc6c9a19d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 993 additions and 937 deletions

View file

@ -1,5 +1,7 @@
import { langs } from '$lib/constants';
import messages from '$lib/i18n/en.json';
import { exec as execCallback } from 'node:child_process';
import { readFileSync, readdirSync } from 'node:fs';
import { promisify } from 'node:util';
type Messages = { [key: string]: string | Messages };
@ -30,4 +32,24 @@ describe('i18n', () => {
// Only translations directly using the store seem to get extracted
expect({ ...extractedMessages, ...existingMessages }).toEqual(existingMessages);
});
describe('loaders', () => {
const languageFiles = readdirSync('src/lib/i18n').sort();
for (const filename of languageFiles) {
test(`${filename} should have a loader`, async () => {
const code = filename.replaceAll('.json', '');
const item = langs.find((lang) => lang.weblateCode === code || lang.code === code);
expect(item, `${filename} has no loader`).toBeDefined();
if (!item) {
return;
}
// verify it loads the right file
const module: { default?: unknown } = await item.loader();
const translations = JSON.stringify(module.default, null, 2).trim();
const content = readFileSync(`src/lib/i18n/${filename}`).toString().trim();
expect(translations === content, `${item.name} did not load ${filename}`).toEqual(true);
});
}
});
});