test(i18n): enforce catalogue key placeholder and nonblank parity

This commit is contained in:
cesnimda
2026-11-02 23:20:25 +01:00
parent 557efde073
commit 1756273bc1
4 changed files with 32 additions and 0 deletions
@@ -0,0 +1,21 @@
import { translations } from './i18n/translations';
const placeholders = (text: string) => [...new Set(text.match(/\{\w+\}/g) ?? [])].sort();
test('English and Bokmål expose the same UI message keys', () => {
expect(Object.keys(translations.nb).sort()).toEqual(Object.keys(translations.en).sort());
});
test('Bokmål preserves every English substitution variable', () => {
const mismatches = Object.entries(translations.en).filter(([key, text]) =>
JSON.stringify(placeholders(text)) !== JSON.stringify(placeholders(translations.nb[key as keyof typeof translations.en]))
).map(([key]) => key);
expect(mismatches).toEqual([]);
});
test('supported UI catalogues contain no blank messages', () => {
const blanks = Object.entries(translations).flatMap(([language, messages]) =>
Object.entries(messages).filter(([, text]) => !text.trim()).map(([key]) => `${language}.${key}`)
);
expect(blanks).toEqual([]);
});