|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { de } from '../../packages/shared/src/i18n/messages/de'; |
| 3 | +import { en } from '../../packages/shared/src/i18n/messages/en'; |
| 4 | +import { es } from '../../packages/shared/src/i18n/messages/es'; |
| 5 | +import { ja } from '../../packages/shared/src/i18n/messages/ja'; |
| 6 | +import { ko } from '../../packages/shared/src/i18n/messages/ko'; |
| 7 | +import { pt } from '../../packages/shared/src/i18n/messages/pt'; |
| 8 | +import { zhCN } from '../../packages/shared/src/i18n/messages/zh-CN'; |
| 9 | +import { LanguageCode, SHELL_LOCALES } from '@ranuts/shared/i18n'; |
| 10 | + |
| 11 | +/** |
| 12 | + * Every language this site claims to ship says everything. |
| 13 | + * |
| 14 | + * The compiler only enforces that for en and zh-CN: they are typed |
| 15 | + * `I18nMessages`, the other five are `Partial<I18nMessages>` so that staying |
| 16 | + * complete is a choice rather than something a half-finished translation |
| 17 | + * cannot compile against. The cost of that choice is that a missing key is |
| 18 | + * silent -- `t()` falls back to English, which reads like a translation |
| 19 | + * somebody chose rather than one nobody wrote. |
| 20 | + * |
| 21 | + * CLAUDE.md and the README both say all seven tables are complete. This is |
| 22 | + * what makes that true rather than aspirational, and it is the check a new UI |
| 23 | + * string has to pass: add it to en, and this fails until the other six have it. |
| 24 | + * |
| 25 | + * Imported from source rather than from the built package: the tables are |
| 26 | + * internal, and the point is to compare them against each other. |
| 27 | + */ |
| 28 | +// Keyed by the internal language code, which is what SHELL_LOCALES holds -- |
| 29 | +// `zh` there, `zh-CN` as a file name and as the tag the vendor wants. |
| 30 | +const asTable = (table: object): Record<string, unknown> => table as Record<string, unknown>; |
| 31 | + |
| 32 | +const TABLES: Record<string, Record<string, unknown>> = { |
| 33 | + [LanguageCode.EN]: asTable(en), |
| 34 | + [LanguageCode.ZH]: asTable(zhCN), |
| 35 | + [LanguageCode.JA]: asTable(ja), |
| 36 | + [LanguageCode.KO]: asTable(ko), |
| 37 | + [LanguageCode.DE]: asTable(de), |
| 38 | + [LanguageCode.ES]: asTable(es), |
| 39 | + [LanguageCode.PT]: asTable(pt), |
| 40 | +}; |
| 41 | + |
| 42 | +describe('message tables', () => { |
| 43 | + it('covers every language the shell offers (and nothing it does not)', () => { |
| 44 | + expect(Object.keys(TABLES).sort()).toEqual([...SHELL_LOCALES].sort()); |
| 45 | + }); |
| 46 | + |
| 47 | + it('gives every language every string en has', () => { |
| 48 | + const reference = Object.keys(en).sort(); |
| 49 | + expect(reference.length).toBeGreaterThan(50); |
| 50 | + for (const [locale, table] of Object.entries(TABLES)) { |
| 51 | + const missing = reference.filter((key) => !(key in table)); |
| 52 | + expect(missing, `${locale} is missing ${missing.length} string(s)`).toEqual([]); |
| 53 | + } |
| 54 | + }); |
| 55 | + |
| 56 | + it('has no string a language invented on its own', () => { |
| 57 | + // An extra key is a typo that will never be read -- `t()` looks up by the |
| 58 | + // name en uses. |
| 59 | + const reference = new Set(Object.keys(en)); |
| 60 | + for (const [locale, table] of Object.entries(TABLES)) { |
| 61 | + const extra = Object.keys(table).filter((key) => !reference.has(key)); |
| 62 | + expect(extra, `${locale} has ${extra.length} string(s) en does not`).toEqual([]); |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + it('leaves no string empty', () => { |
| 67 | + for (const [locale, table] of Object.entries(TABLES)) { |
| 68 | + const blank = Object.entries(table) |
| 69 | + .filter(([, value]) => typeof value === 'string' && value.trim() === '') |
| 70 | + .map(([key]) => key); |
| 71 | + expect(blank, `${locale} has blank string(s)`).toEqual([]); |
| 72 | + } |
| 73 | + }); |
| 74 | +}); |
0 commit comments