@@ -48,6 +48,7 @@ Everything lives under `packages/`:
4848
4949### Optional adapters / supporting packages
5050
51+ - ` packages/qti2-i18n ` : Internationalization (i18n) system for player UI (type-safe translations, runtime locale switching)
5152- ` packages/qti2-typeset-katex ` : KaTeX typesetting adapter (host-provided ` typeset() ` function)
5253- ` packages/qti-processing ` : response processing operators/templates used by the item player
5354- ` packages/qti2-player-elements ` , ` packages/web-component-loaders ` : web-component build/load helpers
@@ -244,6 +245,102 @@ Key references:
244245
245246---
246247
248+ ## Internationalization (i18n)
249+
250+ > ** Status** : Production-ready
251+ > ** Package** : ` @pie-qti/qti2-i18n `
252+
253+ ### Overview
254+
255+ The PIE-QTI player includes a lightweight, type-safe internationalization system for translating player UI strings (buttons, labels, error messages, ARIA text, etc.).
256+
257+ ** Note** : This system translates the ** player interface** , not QTI assessment content. Assessments are authored in the content creator's chosen language.
258+
259+ ### Key features
260+
261+ - ** Type-safe translations** : TypeScript autocomplete for all message keys
262+ - ** Runtime locale switching** : Change language without page reload or component remount
263+ - ** Reactive updates** : Svelte store integration automatically updates all UI text
264+ - ** Web Component compatible** : Works within Shadow DOM boundaries via context API
265+ - ** Small bundle size** : <10 KB gzipped (core + default English locale)
266+ - ** On-demand loading** : Additional locales loaded asynchronously when needed
267+
268+ ### Supported locales (Priority 1)
269+
270+ | Locale Code | Language |
271+ | -------------| -----------------------------|
272+ | ` en-US ` | English (United States) |
273+ | ` es-ES ` | Spanish (Spain) |
274+ | ` fr-FR ` | French (France) |
275+ | ` de-DE ` | German (Germany) |
276+ | ` pt-BR ` | Portuguese (Brazil) |
277+
278+ ### Architecture
279+
280+ The i18n system consists of:
281+
282+ 1 . ** Core I18n class** (` I18n.ts ` ) - Message lookup, interpolation, pluralization, number/date formatting
283+ 2 . ** Svelte store integration** (` store.ts ` ) - Reactive ` $t ` , ` $formatNumber ` , ` $formatDate ` stores
284+ 3 . ** Context API** (` context.ts ` ) - Pass i18n instance through component tree (including Shadow DOM)
285+ 4 . ** Locale files** (` locales/*.ts ` ) - TypeScript modules with structured translation messages
286+ 5 . ** LocaleSwitcher component** - Dropdown UI for runtime locale selection
287+
288+ ### Usage in components
289+
290+ ``` svelte
291+ <script lang="ts">
292+ import { t } from '@pie-qti/qti2-i18n';
293+ </script>
294+
295+ <!-- Simple translation -->
296+ <button>{$t('common.submit')}</button>
297+
298+ <!-- With interpolation -->
299+ <p>{$t('assessment.question', { current: 1, total: 10 })}</p>
300+
301+ <!-- Error messages -->
302+ <div class="alert">{$t('interactions.upload.errorInvalidType', { types: 'pdf, jpg' })}</div>
303+ ```
304+
305+ ### Initialization
306+
307+ Initialize i18n in the application root (e.g., ` +layout.svelte ` ):
308+
309+ ``` typescript
310+ import { initI18n } from ' @pie-qti/qti2-i18n' ;
311+
312+ const i18n = initI18n (' en-US' );
313+ await i18n .loadLocale (' en-US' );
314+ ```
315+
316+ ### Message namespaces
317+
318+ Translations are organized by feature:
319+
320+ - ` common.* ` - Shared UI text (Submit, Cancel, Next, etc.)
321+ - ` units.* ` - Unit formatting (bytes, KB, seconds, etc.)
322+ - ` validation.* ` - Form validation messages
323+ - ` interactions.* ` - QTI interaction-specific text (organized by interaction type)
324+ - ` assessment.* ` - Assessment player UI (navigation, sections, timer, feedback)
325+ - ` accessibility.* ` - ARIA labels and screen reader announcements
326+
327+ ### Type safety
328+
329+ Message keys are automatically typed from the English locale structure. IDEs provide autocomplete and compile-time validation:
330+
331+ ``` typescript
332+ $t (' common.submit' ) // ✅ Valid
333+ $t (' invalid.key' ) // ❌ TypeScript error
334+ ```
335+
336+ ### Key references
337+
338+ - ` packages/qti2-i18n/README.md ` - Full API documentation and migration guide
339+ - ` docs/i18n-design-plan.md ` - Detailed design document with architecture rationale
340+ - ` packages/qti2-i18n/src/locales/en-US.ts ` - Complete list of available translation keys
341+
342+ ---
343+
247344## Transformations: QTI ↔ PIE
248345
249346> ** Status** : Under active development
0 commit comments