/** * i18n (Phase 6): all ten locale tables load, `t()` falls back to English * (mirroring gen-l10n), and the locale store switches the active table. */ import { describe, expect, it } from 'vitest'; import { get } from 'svelte/store'; import { en } from '$lib/i18n/en'; import { de } from '$lib/i18n/de'; import { es } from '$lib/i18n/es'; import { fr } from '$lib/i18n/fr'; import { ko } from '$lib/i18n/ko'; import { pl } from '$lib/i18n/pl'; import { ru } from '$lib/i18n/ru'; import { th } from '$lib/i18n/th'; import { zh } from '$lib/i18n/zh'; import { zh_Hant } from '$lib/i18n/zh_Hant'; import { availableLocales, locale, t, hasLocaleKey, type Locale } from '$lib/i18n/index'; const tables: Record> = { en, de, es, fr, ko, pl, ru, th, zh, zh_Hant }; describe('i18n', () => { it('offers the ten locales from the reference app', () => { expect(availableLocales).toEqual([ 'en', 'de', 'es', 'fr', 'ko', 'pl', 'ru', 'th', 'zh', 'zh_Hant' ]); }); it('covers every table with non-empty strings (en ⊇ others, as in the arbs)', () => { for (const l of availableLocales) { const table = tables[l]; const entries = Object.entries(table); expect(entries.length, `${l} has keys`).toBeGreaterThan(100); for (const [key, value] of entries) { expect(typeof value, `${l}.${key}`).toBe('string'); expect((value as string).length, `${l}.${key} non-empty`).toBeGreaterThan(0); } } }); it('translates from the active locale and falls back to English', () => { locale.set('de'); // `settingsNoInit` exists in both en and de (with different text). expect(t('settingsNoInit')).toBe(de['settingsNoInit']); expect(t('settingsNoInit')).not.toBe(en['settingsNoInit']); locale.set('en'); }); it('falls back to English for a key a locale lacks', () => { locale.set('de'); // A web-only key: only in the English table. expect(t('styleGloomhaven')).toBe('Gloomhaven'); expect(hasLocaleKey('styleGloomhaven')).toBe(false); expect(hasLocaleKey('settingsNoInit')).toBe(true); locale.set('en'); }); it('returns the key itself when it is unknown everywhere', () => { expect(t('noSuchKeyAnywhere')).toBe('noSuchKeyAnywhere'); }); it('substitutes variables', () => { expect(t('undoWithDescription', { description: 'Add Blinkblade' })).toBe( 'Undo: Add Blinkblade' ); }); });