@pie-qti/i18n 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +264 -0
  2. package/README.md +402 -0
  3. package/dist/core/I18n.d.ts +83 -0
  4. package/dist/core/I18n.d.ts.map +1 -0
  5. package/dist/core/I18n.js +203 -0
  6. package/dist/core/I18n.js.map +1 -0
  7. package/dist/core/I18nProvider.d.ts +64 -0
  8. package/dist/core/I18nProvider.d.ts.map +1 -0
  9. package/dist/core/I18nProvider.js +9 -0
  10. package/dist/core/I18nProvider.js.map +1 -0
  11. package/dist/core/types.d.ts +20 -0
  12. package/dist/core/types.d.ts.map +1 -0
  13. package/dist/core/types.js +5 -0
  14. package/dist/core/types.js.map +1 -0
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/locales/ar-SA.d.ts +763 -0
  20. package/dist/locales/ar-SA.d.ts.map +1 -0
  21. package/dist/locales/ar-SA.js +796 -0
  22. package/dist/locales/ar-SA.js.map +1 -0
  23. package/dist/locales/en-US.d.ts +731 -0
  24. package/dist/locales/en-US.d.ts.map +1 -0
  25. package/dist/locales/en-US.js +764 -0
  26. package/dist/locales/en-US.js.map +1 -0
  27. package/dist/locales/es-ES.d.ts +734 -0
  28. package/dist/locales/es-ES.d.ts.map +1 -0
  29. package/dist/locales/es-ES.js +758 -0
  30. package/dist/locales/es-ES.js.map +1 -0
  31. package/dist/locales/fr-FR.d.ts +733 -0
  32. package/dist/locales/fr-FR.d.ts.map +1 -0
  33. package/dist/locales/fr-FR.js +757 -0
  34. package/dist/locales/fr-FR.js.map +1 -0
  35. package/dist/locales/nl-NL.d.ts +733 -0
  36. package/dist/locales/nl-NL.d.ts.map +1 -0
  37. package/dist/locales/nl-NL.js +757 -0
  38. package/dist/locales/nl-NL.js.map +1 -0
  39. package/dist/locales/ro-RO.d.ts +733 -0
  40. package/dist/locales/ro-RO.d.ts.map +1 -0
  41. package/dist/locales/ro-RO.js +757 -0
  42. package/dist/locales/ro-RO.js.map +1 -0
  43. package/dist/locales/th-TH.d.ts +733 -0
  44. package/dist/locales/th-TH.d.ts.map +1 -0
  45. package/dist/locales/th-TH.js +758 -0
  46. package/dist/locales/th-TH.js.map +1 -0
  47. package/dist/locales/zh-CN.d.ts +731 -0
  48. package/dist/locales/zh-CN.d.ts.map +1 -0
  49. package/dist/locales/zh-CN.js +764 -0
  50. package/dist/locales/zh-CN.js.map +1 -0
  51. package/dist/providers/SvelteI18nProvider.d.ts +40 -0
  52. package/dist/providers/SvelteI18nProvider.d.ts.map +1 -0
  53. package/dist/providers/SvelteI18nProvider.js +133 -0
  54. package/dist/providers/SvelteI18nProvider.js.map +1 -0
  55. package/docs/ADVANCED_FEATURES.md +556 -0
  56. package/docs/COMPONENT_PATTERNS.md +896 -0
  57. package/docs/INTEGRATION_GUIDE.md +695 -0
  58. package/package.json +42 -0
  59. package/scripts/check-translations.ts +289 -0
  60. package/scripts/scan-hardcoded-strings.ts +266 -0
  61. package/src/components/LocaleSwitcher.svelte +145 -0
  62. package/src/components/README.md +224 -0
  63. package/src/core/I18n.ts +235 -0
  64. package/src/core/I18nProvider.ts +68 -0
  65. package/src/core/types.ts +45 -0
  66. package/src/index.ts +22 -0
  67. package/src/locales/ar-SA.ts +860 -0
  68. package/src/locales/en-US.ts +828 -0
  69. package/src/locales/es-ES.ts +816 -0
  70. package/src/locales/fr-FR.ts +815 -0
  71. package/src/locales/nl-NL.ts +815 -0
  72. package/src/locales/ro-RO.ts +815 -0
  73. package/src/locales/th-TH.ts +816 -0
  74. package/src/locales/zh-CN.ts +828 -0
  75. package/src/providers/SvelteI18nProvider.ts +170 -0
  76. package/tests/i18n.test.ts +146 -0
  77. package/tsconfig.json +10 -0
  78. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,264 @@
1
+ $ bun run check-translations && tsc
2
+ $ bun run scripts/check-translations.ts
3
+ 🔍 Translation Coverage Checker
4
+
5
+ 📁 Locales directory: /home/runner/work/pie-qti/pie-qti/packages/i18n/src/locales
6
+ 📖 Reference locale: en-US
7
+
8
+ ✓ Loaded reference: en-US (592 keys)
9
+
10
+
11
+ ================================================================================
12
+ 📋 Locale: zh-CN
13
+ ================================================================================
14
+ Coverage: 100.0% (592/592 keys)
15
+
16
+ ⚠️ Potentially Untranslated (13) - Same value as en-US:
17
+ ────────────────────────────────────────────────────────────────────────────────
18
+ • demo.csv
19
+ • demo.json
20
+ • interactions.custom.xml
21
+ • interactions.gapMatch.filledGapAriaLabel
22
+ • interactions.inline.placeholder
23
+ • interactions.media.currentTime
24
+ • interactions.upload.fileSizeKb
25
+ • interactions.upload.fileSizeMb
26
+ • transform.badges.qti
27
+ • transform.player.esm
28
+ • transform.player.iife
29
+ • units.kilobytes
30
+ • units.megabytes
31
+
32
+
33
+ ================================================================================
34
+ 📋 Locale: th-TH
35
+ ================================================================================
36
+ Coverage: 100.0% (592/592 keys)
37
+
38
+ ⚠️ Potentially Untranslated (13) - Same value as en-US:
39
+ ────────────────────────────────────────────────────────────────────────────────
40
+ • demo.csv
41
+ • demo.json
42
+ • interactions.custom.xml
43
+ • interactions.inline.placeholder
44
+ • interactions.media.currentTime
45
+ • interactions.upload.fileSizeKb
46
+ • interactions.upload.fileSizeMb
47
+ • transform.badges.qti
48
+ • transform.player.esm
49
+ • transform.player.iife
50
+ • transform.samples.hasManifest
51
+ • units.kilobytes
52
+ • units.megabytes
53
+
54
+
55
+ ================================================================================
56
+ 📋 Locale: nl-NL
57
+ ================================================================================
58
+ Coverage: 100.0% (592/592 keys)
59
+
60
+ ⚠️ Potentially Untranslated (55) - Same value as en-US:
61
+ ────────────────────────────────────────────────────────────────────────────────
62
+ • assessment.completion.percentage
63
+ • assessment.feedback.correct
64
+ • assessment.feedback.incorrect
65
+ • assessment.feedback.score
66
+ • common.details
67
+ • common.status
68
+ • demo.csv
69
+ • demo.home
70
+ • demo.iframeDemo
71
+ • demo.itemDemo
72
+ • demo.json
73
+ • demo.likertDemo
74
+ • demo.pluginDemo
75
+ • demo.score
76
+ • interactions.choice.correct
77
+ • interactions.custom.promptLabel
78
+ • interactions.custom.xml
79
+ • interactions.graphicGapMatch.hotspot
80
+ • interactions.graphicOrder.itemLabel
81
+ • interactions.inline.placeholder
82
+ • interactions.media.currentTime
83
+ • interactions.media.volume
84
+ • interactions.positionObject.maximumAllowed
85
+ • interactions.slider.max
86
+ • interactions.slider.min
87
+ • interactions.upload.fileSize
88
+ • interactions.upload.fileSizeKb
89
+ • interactions.upload.fileSizeMb
90
+ • plurals.items.one
91
+ • plurals.items.other
92
+ • transform.analysis.passages
93
+ • transform.appName
94
+ • transform.badges.qti
95
+ • transform.detail.items
96
+ • transform.detail.passages
97
+ • transform.detail.type
98
+ • transform.home
99
+ • transform.items.itemsCount
100
+ • transform.items.title
101
+ • transform.player.browse
102
+ • transform.player.debugConfig
103
+ • transform.player.esm
104
+ • transform.player.evaluate
105
+ • transform.player.gather
106
+ • transform.player.iife
107
+ • transform.player.instructor
108
+ • transform.player.student
109
+ • transform.player.view
110
+ • transform.samples.hasManifest
111
+ • transform.samples.itemCount
112
+ • transform.sessions.status
113
+ • transform.transformed.items
114
+ • units.bytes
115
+ • units.kilobytes
116
+ • units.megabytes
117
+
118
+
119
+ ================================================================================
120
+ 📋 Locale: ar-SA
121
+ ================================================================================
122
+ Coverage: 100.0% (592/592 keys)
123
+
124
+ ⚠️ Potentially Untranslated (8) - Same value as en-US:
125
+ ────────────────────────────────────────────────────────────────────────────────
126
+ • demo.csv
127
+ • demo.json
128
+ • interactions.custom.xml
129
+ • interactions.inline.placeholder
130
+ • interactions.media.currentTime
131
+ • transform.badges.qti
132
+ • transform.player.esm
133
+ • transform.player.iife
134
+
135
+
136
+ ================================================================================
137
+ 📋 Locale: es-ES
138
+ ================================================================================
139
+ Coverage: 100.0% (592/592 keys)
140
+
141
+ ⚠️ Potentially Untranslated (18) - Same value as en-US:
142
+ ────────────────────────────────────────────────────────────────────────────────
143
+ • common.error
144
+ • demo.csv
145
+ • demo.json
146
+ • demo.tutor
147
+ • demo.variable
148
+ • interactions.custom.xml
149
+ • interactions.inline.placeholder
150
+ • interactions.media.currentTime
151
+ • interactions.upload.fileSize
152
+ • interactions.upload.fileSizeKb
153
+ • interactions.upload.fileSizeMb
154
+ • transform.badges.qti
155
+ • transform.player.esm
156
+ • transform.player.iife
157
+ • transform.player.instructor
158
+ • units.bytes
159
+ • units.kilobytes
160
+ • units.megabytes
161
+
162
+
163
+ ================================================================================
164
+ 📋 Locale: ro-RO
165
+ ================================================================================
166
+ Coverage: 100.0% (592/592 keys)
167
+
168
+ ⚠️ Potentially Untranslated (25) - Same value as en-US:
169
+ ────────────────────────────────────────────────────────────────────────────────
170
+ • common.status
171
+ • demo.csv
172
+ • demo.format
173
+ • demo.json
174
+ • demo.tutor
175
+ • interactions.custom.promptLabel
176
+ • interactions.custom.xml
177
+ • interactions.graphicGapMatch.hotspot
178
+ • interactions.inline.placeholder
179
+ • interactions.media.currentTime
180
+ • interactions.upload.fileSizeKb
181
+ • interactions.upload.fileSizeMb
182
+ • transform.appName
183
+ • transform.badges.qti
184
+ • transform.player.browse
185
+ • transform.player.esm
186
+ • transform.player.evaluate
187
+ • transform.player.gather
188
+ • transform.player.iife
189
+ • transform.player.instructor
190
+ • transform.player.view
191
+ • transform.samples.hasManifest
192
+ • transform.sessions.status
193
+ • units.kilobytes
194
+ • units.megabytes
195
+
196
+
197
+ ================================================================================
198
+ 📋 Locale: fr-FR
199
+ ================================================================================
200
+ Coverage: 100.0% (592/592 keys)
201
+
202
+ ⚠️ Potentially Untranslated (42) - Same value as en-US:
203
+ ────────────────────────────────────────────────────────────────────────────────
204
+ • assessment.feedback.correct
205
+ • assessment.feedback.incorrect
206
+ • assessment.sectionDefault
207
+ • assessment.sections.title
208
+ • common.question
209
+ • demo.csv
210
+ • demo.format
211
+ • demo.json
212
+ • demo.score
213
+ • demo.variable
214
+ • interactions.associate.associations
215
+ • interactions.associate.associationsCount
216
+ • interactions.choice.correct
217
+ • interactions.custom.xml
218
+ • interactions.inline.placeholder
219
+ • interactions.media.currentTime
220
+ • interactions.media.pause
221
+ • interactions.media.volume
222
+ • interactions.selectPoint.point
223
+ • plurals.questions.one
224
+ • plurals.questions.other
225
+ • transform.analysis.packages
226
+ • transform.analysis.passages
227
+ • transform.analysis.tests
228
+ • transform.assessmentPreview.configuration
229
+ • transform.assessmentPreview.sections
230
+ • transform.badges.qti
231
+ • transform.detail.actions
232
+ • transform.detail.package
233
+ • transform.detail.passages
234
+ • transform.detail.tests
235
+ • transform.detail.type
236
+ • transform.player.browse
237
+ • transform.player.esm
238
+ • transform.player.evaluate
239
+ • transform.player.gather
240
+ • transform.player.iife
241
+ • transform.player.view
242
+ • transform.samples.hasManifest
243
+ • transform.sessions.packages
244
+ • transform.sessions.session
245
+ • units.minutes
246
+
247
+
248
+ ================================================================================
249
+ 📊 SUMMARY TABLE
250
+ ================================================================================
251
+
252
+ Locale Coverage Missing Extra Untranslated
253
+ ────────────────────────────────────────────────────────────────────────────────
254
+ ✅ zh-CN 100.0% 0 0 13
255
+ ✅ th-TH 100.0% 0 0 13
256
+ ✅ nl-NL 100.0% 0 0 55
257
+ ✅ ar-SA 100.0% 0 0 8
258
+ ✅ es-ES 100.0% 0 0 18
259
+ ✅ ro-RO 100.0% 0 0 25
260
+ ✅ fr-FR 100.0% 0 0 42
261
+ ────────────────────────────────────────────────────────────────────────────────
262
+
263
+ ✅ All locales have complete translation coverage!
264
+
package/README.md ADDED
@@ -0,0 +1,402 @@
1
+ # @pie-qti/i18n
2
+
3
+ Lightweight, type-safe internationalization (i18n) package for the PIE-QTI player ecosystem.
4
+
5
+ ## Features
6
+
7
+ - ✅ **Type-Safe Translations** - TypeScript autocomplete for all message keys
8
+ - ✅ **Locale Persistence** - Locale persists across page reloads via localStorage
9
+ - ✅ **Framework Agnostic** - Core provider works with any JavaScript framework
10
+ - ✅ **Svelte Integration** - Simple `$derived` pattern for Svelte 5 components
11
+ - ✅ **Web Component Compatible** - Works within Shadow DOM boundaries
12
+ - ✅ **Small Bundle Size** - <10 KB gzipped for core + default locale
13
+ - ✅ **On-Demand Loading** - Load additional locales asynchronously
14
+ - ✅ **Built-in Formatting** - Number and date formatting via `Intl` APIs
15
+ - ✅ **Custom Translations** - Override or extend framework translations
16
+ - ✅ **6 Languages Supported** - en-US (complete), es-ES, fr-FR, nl-NL, ro-RO, th-TH
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ bun add @pie-qti/i18n
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. Create i18n Provider
27
+
28
+ ```typescript
29
+ import { DefaultI18nProvider } from '@pie-qti/i18n';
30
+
31
+ // Create provider with default locale
32
+ const i18n = new DefaultI18nProvider('en-US');
33
+
34
+ // Optional: Load additional locales
35
+ await i18n.loadLocale('es-ES');
36
+ await i18n.loadLocale('fr-FR');
37
+ ```
38
+
39
+ ### 2. Use in Components (Svelte 5)
40
+
41
+ ```svelte
42
+ <script lang="ts">
43
+ import type { I18nProvider } from '@pie-qti/i18n';
44
+
45
+ interface Props {
46
+ i18n?: I18nProvider; // Always optional
47
+ }
48
+
49
+ let { i18n }: Props = $props();
50
+
51
+ // Simple pattern - locale changes trigger page refresh
52
+ const translations = $derived({
53
+ submit: i18n?.t('common.submit') ?? 'Submit',
54
+ cancel: i18n?.t('common.cancel') ?? 'Cancel'
55
+ });
56
+ </script>
57
+
58
+ <button>{translations.submit}</button>
59
+ <button>{translations.cancel}</button>
60
+ ```
61
+
62
+ **Note:** Translations are evaluated once when the component loads. If you need to update translations, the page will reload when the locale changes.
63
+
64
+ ### 3. Switch Locales
65
+
66
+ ```typescript
67
+ // Switch to Spanish (triggers page reload)
68
+ await i18n.setLocale('es-ES');
69
+
70
+ // Locale is stored in localStorage and persists across reloads
71
+ // On next page load, i18n will automatically use 'es-ES'
72
+ ```
73
+
74
+ **Important:** Calling `setLocale()` stores the locale in localStorage and triggers a page reload. This simplifies the codebase by eliminating complex reactivity patterns.
75
+
76
+ ## API Reference
77
+
78
+ ### Core Provider
79
+
80
+ #### `I18nProvider` Interface
81
+
82
+ The framework-agnostic interface for i18n providers:
83
+
84
+ ```typescript
85
+ interface I18nProvider {
86
+ getLocale(): string;
87
+ setLocale(locale: string): Promise<void>;
88
+ loadLocale(locale: string): Promise<void>;
89
+ t(key: string, values?: Record<string, any>): string;
90
+ formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
91
+ formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string;
92
+ }
93
+ ```
94
+
95
+ #### `DefaultI18nProvider`
96
+
97
+ Basic implementation without framework-specific features:
98
+
99
+ ```typescript
100
+ import { DefaultI18nProvider } from '@pie-qti/i18n';
101
+
102
+ // Create with default locale
103
+ const i18n = new DefaultI18nProvider('en-US');
104
+
105
+ // With custom messages
106
+ const customMessages = {
107
+ 'es-ES': {
108
+ common: { submit: 'Enviar' }
109
+ }
110
+ };
111
+ const i18n = new DefaultI18nProvider('en-US', customMessages);
112
+
113
+ // Load additional locales
114
+ await i18n.loadLocale('es-ES');
115
+
116
+ // Switch locales
117
+ await i18n.setLocale('es-ES');
118
+
119
+ // Translate
120
+ const text = i18n.t('common.submit');
121
+ const interpolated = i18n.t('assessment.question', { current: 1, total: 10 });
122
+ ```
123
+
124
+ #### `SvelteI18nProvider`
125
+
126
+ Svelte-specific wrapper that extends `I18nProvider`:
127
+
128
+ ```typescript
129
+ import { createDefaultSvelteI18nProvider } from '@pie-qti/i18n';
130
+
131
+ // Create Svelte provider
132
+ const i18n = await createDefaultSvelteI18nProvider('en-US');
133
+
134
+ // Same API as I18nProvider
135
+ const text = i18n.t('common.submit');
136
+ await i18n.setLocale('es-ES'); // Triggers page reload
137
+
138
+ // Deprecated reactive stores (kept for backwards compatibility)
139
+ // Note: These are no longer needed since locale changes trigger page reload
140
+ const { locale, t$, plural$, formatNumber$, formatDate$ } = i18n;
141
+ ```
142
+
143
+ **Migration Note:** The reactive stores (`locale`, `t$`, `plural$`, etc.) are deprecated. Use the direct methods (`t()`, `plural()`, etc.) with `$derived` instead. See the Quick Start section for the recommended pattern.
144
+
145
+ ### Supported Locales
146
+
147
+ The framework currently includes 6 locales:
148
+
149
+ | Locale Code | Language | Status |
150
+ |-------------|---------------------------|--------------------------|
151
+ | `en-US` | English (United States) | ✅ Complete (300+ keys) |
152
+ | `es-ES` | Spanish (Spain) | 🚧 ~80% complete |
153
+ | `fr-FR` | French (France) | 🚧 ~70% complete |
154
+ | `nl-NL` | Dutch (Netherlands) | 🚧 ~30% complete |
155
+ | `ro-RO` | Romanian (Romania) | 🚧 ~30% complete |
156
+ | `th-TH` | Thai (Thailand) | 🚧 ~30% complete |
157
+
158
+ **Note:** Additional locales can be provided via custom translations (see below).
159
+
160
+ ## Message Keys
161
+
162
+ All translation keys are type-safe. Your IDE will provide autocomplete for available keys:
163
+
164
+ ```typescript
165
+ // ✅ Valid keys (autocomplete provided)
166
+ $t('common.submit')
167
+ $t('interactions.upload.label')
168
+ $t('assessment.question', { current: 1, total: 10 })
169
+
170
+ // ❌ TypeScript error - invalid key
171
+ $t('invalid.key')
172
+ ```
173
+
174
+ ### Common Message Namespaces
175
+
176
+ - `common.*` - Shared UI text (buttons, labels)
177
+ - `units.*` - Unit formatting (bytes, time)
178
+ - `validation.*` - Form validation messages
179
+ - `interactions.*` - QTI interaction-specific text
180
+ - `assessment.*` - Assessment player UI
181
+ - `accessibility.*` - ARIA labels and screen reader text
182
+
183
+ See [en-US.ts](./src/locales/en-US.ts) for the complete list of available keys.
184
+
185
+ ## Custom Translations
186
+
187
+ You can provide your own translations or override framework translations:
188
+
189
+ ```typescript
190
+ import { DefaultI18nProvider } from '@pie-qti/i18n';
191
+
192
+ const customMessages = {
193
+ // Add a new locale
194
+ 'de-DE': {
195
+ common: {
196
+ submit: 'Einreichen',
197
+ next: 'Weiter',
198
+ previous: 'Zurück',
199
+ },
200
+ interactions: {
201
+ upload: {
202
+ label: 'Datei hochladen',
203
+ },
204
+ }
205
+ },
206
+ // Override specific framework translations
207
+ 'en-US': {
208
+ common: {
209
+ submit: 'Send Answer', // Brand-specific terminology
210
+ }
211
+ }
212
+ };
213
+
214
+ const i18n = new DefaultI18nProvider('en-US', customMessages);
215
+ ```
216
+
217
+ Custom translations have higher priority than framework translations, so you can selectively override specific keys while keeping the rest.
218
+
219
+ ## Component Integration
220
+
221
+ ### Recommended Pattern (Svelte 5)
222
+
223
+ The recommended approach is simple: use `$derived` to create memoized translations.
224
+
225
+ ```svelte
226
+ <script lang="ts">
227
+ import type { I18nProvider } from '@pie-qti/i18n';
228
+
229
+ interface Props {
230
+ i18n?: I18nProvider;
231
+ }
232
+
233
+ let { i18n }: Props = $props();
234
+
235
+ // Memoized translations - evaluated once when component loads
236
+ const translations = $derived({
237
+ submit: i18n?.t('common.submit') ?? 'Submit',
238
+ cancel: i18n?.t('common.cancel') ?? 'Cancel'
239
+ });
240
+ </script>
241
+
242
+ <button class="btn btn-primary">{translations.submit}</button>
243
+ <button class="btn btn-outline">{translations.cancel}</button>
244
+ ```
245
+
246
+ ### Inline Pattern (For Simple Cases)
247
+
248
+ For one-off translations, you can call `t()` directly:
249
+
250
+ ```svelte
251
+ <button>{i18n?.t('common.submit') ?? 'Submit'}</button>
252
+ ```
253
+
254
+ ### Helper Pattern (For Cleaner Code)
255
+
256
+ Create a translation helper for repeated use:
257
+
258
+ ```svelte
259
+ <script lang="ts">
260
+ const t = $derived((key: string, fallback: string) => i18n?.t(key) ?? fallback);
261
+ </script>
262
+
263
+ <button>{t('common.submit', 'Submit')}</button>
264
+ <button>{t('common.cancel', 'Cancel')}</button>
265
+ ```
266
+
267
+ ### Web Components
268
+
269
+ Web components receive i18n as a property:
270
+
271
+ ```typescript
272
+ interface Props {
273
+ i18n?: I18nProvider;
274
+ }
275
+
276
+ let { i18n = $bindable() }: Props = $props();
277
+
278
+ const t = $derived((key: string, fallback: string) => i18n?.t(key) ?? fallback);
279
+ ```
280
+
281
+ **Note:** No manual subscriptions or reactivity tracking needed. Locale changes trigger a page reload, so components always render with the correct locale.
282
+
283
+ ## Bundle Size
284
+
285
+ | Component | Size (gzipped) |
286
+ |-------------------------------|----------------|
287
+ | Core i18n logic | ~2 KB |
288
+ | English locale (en-US) | ~8 KB |
289
+ | Additional locale (on-demand) | ~8 KB each |
290
+ | **Total (default)** | **~10 KB** |
291
+
292
+ ## Documentation
293
+
294
+ For detailed guides, see the `docs/` directory:
295
+
296
+ - **[Integration Guide](./docs/INTEGRATION_GUIDE.md)** - Complete guide for adding i18n to components
297
+ - **[Component Patterns](./docs/COMPONENT_PATTERNS.md)** - Svelte 5 + DaisyUI patterns and examples
298
+ - **[Advanced Features](./docs/ADVANCED_FEATURES.md)** - Pluralization, number & date formatting
299
+ - **[Message Keys](./src/locales/en-US.ts)** - All available translation keys and namespaces
300
+
301
+ ## Development
302
+
303
+ ### Adding New Messages
304
+
305
+ 1. Add to English locale:
306
+
307
+ ```typescript
308
+ // src/locales/en-US.ts
309
+ export default {
310
+ myFeature: {
311
+ newMessage: 'My new message',
312
+ },
313
+ } as const;
314
+ ```
315
+
316
+ 2. Add to other locales (maintain same structure)
317
+
318
+ 3. Run translation coverage checker:
319
+
320
+ ```bash
321
+ bun run check-translations
322
+ ```
323
+
324
+ 4. TypeScript automatically provides type safety for the new key
325
+
326
+ ### Translation Coverage Checker
327
+
328
+ The package includes an automated translation coverage checker that ensures all locales maintain 100% coverage:
329
+
330
+ ```bash
331
+ # Check all locales
332
+ bun run check-translations
333
+
334
+ # Check specific locale
335
+ bun run check-translations:locale=nl-NL
336
+ ```
337
+
338
+ The checker:
339
+
340
+ - ✅ **Automatically discovers** all keys from en-US (no hardcoded lists)
341
+ - ✅ **Automatically detects** all locale files (no configuration)
342
+ - ✅ **Reports missing keys** in other locales
343
+ - ✅ **Detects obsolete keys** that should be removed
344
+ - ✅ **Runs in CI/CD** to block PRs with incomplete translations
345
+
346
+ **Integrated into build:**
347
+
348
+ ```bash
349
+ bun run build # Automatically checks translations first
350
+ ```
351
+
352
+ See [Translation Coverage Documentation](./docs/TRANSLATION_COVERAGE.md) for details.
353
+
354
+ ### Hardcoded String Scanner
355
+
356
+ The package includes a scanner that detects hardcoded English strings in component files that should use i18n:
357
+
358
+ ```bash
359
+ # Scan default components package
360
+ bun run scan-hardcoded
361
+
362
+ # Scan a custom path
363
+ bun run scan-hardcoded --path=../custom-components
364
+ ```
365
+
366
+ The scanner:
367
+
368
+ - ✅ **Detects hardcoded strings** that match translation values in en-US
369
+ - ✅ **Suggests the correct i18n key** to use for each match
370
+ - ✅ **Scans .svelte and .ts files** recursively
371
+ - ✅ **Provides exact replacement code** for each hardcoded string
372
+
373
+ **Example output:**
374
+
375
+ ```text
376
+ 📄 plugins/graphic-order/GraphicOrderInteraction.svelte (1 match)
377
+ ────────────────────────────────────────────────────────────────
378
+ Line 138: <h3>Order (drag to reorder)</h3>
379
+ Use: i18n?.t('interactions.graphicOrder.orderHeading') ?? 'Order (drag to reorder)'
380
+ ```
381
+
382
+ This tool helps maintain consistency by ensuring all user-facing strings use the i18n system.
383
+
384
+ ### Running Tests
385
+
386
+ ```bash
387
+ bun test
388
+ ```
389
+
390
+ ### Building
391
+
392
+ ```bash
393
+ # Build with translation check
394
+ bun run build
395
+
396
+ # Build without translation check (emergency use only)
397
+ bun run build:skip-check
398
+ ```
399
+
400
+ ## License
401
+
402
+ ISC © Renaissance Learning