@pie-qti/i18n 1.0.0-beta.0 → 1.0.0-beta.2

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 (59) hide show
  1. package/README.md +104 -55
  2. package/dist/core/I18n.d.ts +149 -0
  3. package/dist/core/I18n.js +348 -0
  4. package/dist/core/I18n.js.map +1 -0
  5. package/dist/core/I18nProvider.d.ts +91 -0
  6. package/dist/core/I18nProvider.js +9 -0
  7. package/dist/core/I18nProvider.js.map +1 -0
  8. package/dist/core/accessible-text.d.ts +36 -0
  9. package/dist/core/accessible-text.js +54 -0
  10. package/dist/core/accessible-text.js.map +1 -0
  11. package/dist/core/direction.d.ts +39 -0
  12. package/dist/core/direction.js +96 -0
  13. package/dist/core/direction.js.map +1 -0
  14. package/dist/core/language-tags.d.ts +47 -0
  15. package/dist/core/language-tags.js +91 -0
  16. package/dist/core/language-tags.js.map +1 -0
  17. package/dist/core/negotiation.d.ts +41 -0
  18. package/dist/core/negotiation.js +71 -0
  19. package/dist/core/negotiation.js.map +1 -0
  20. package/dist/core/numbering.d.ts +31 -0
  21. package/dist/core/numbering.js +88 -0
  22. package/dist/core/numbering.js.map +1 -0
  23. package/dist/core/pseudo.d.ts +33 -0
  24. package/dist/core/pseudo.js +44 -0
  25. package/dist/core/pseudo.js.map +1 -0
  26. package/dist/core/types.d.ts +29 -0
  27. package/dist/core/types.js +5 -0
  28. package/dist/core/types.js.map +1 -0
  29. package/dist/index.d.ts +17 -0
  30. package/dist/index.js +21 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/locales/ar.d.ts +926 -0
  33. package/dist/locales/ar.js +963 -0
  34. package/dist/locales/ar.js.map +1 -0
  35. package/dist/locales/en.d.ts +870 -0
  36. package/dist/locales/en.js +909 -0
  37. package/dist/locales/en.js.map +1 -0
  38. package/dist/locales/es.d.ts +874 -0
  39. package/dist/locales/es.js +901 -0
  40. package/dist/locales/es.js.map +1 -0
  41. package/dist/locales/fr.d.ts +873 -0
  42. package/dist/locales/fr.js +900 -0
  43. package/dist/locales/fr.js.map +1 -0
  44. package/dist/locales/nl.d.ts +872 -0
  45. package/dist/locales/nl.js +898 -0
  46. package/dist/locales/nl.js.map +1 -0
  47. package/dist/locales/ro.d.ts +873 -0
  48. package/dist/locales/ro.js +900 -0
  49. package/dist/locales/ro.js.map +1 -0
  50. package/dist/locales/th.d.ts +872 -0
  51. package/dist/locales/th.js +899 -0
  52. package/dist/locales/th.js.map +1 -0
  53. package/dist/locales/zh-Hans.d.ts +870 -0
  54. package/dist/locales/zh-Hans.js +905 -0
  55. package/dist/locales/zh-Hans.js.map +1 -0
  56. package/dist/providers/SvelteI18nProvider.d.ts +58 -0
  57. package/dist/providers/SvelteI18nProvider.js +102 -0
  58. package/dist/providers/SvelteI18nProvider.js.map +1 -0
  59. package/package.json +5 -3
package/README.md CHANGED
@@ -5,7 +5,8 @@ Lightweight, type-safe internationalization (i18n) package for the PIE-QTI playe
5
5
  ## Features
6
6
 
7
7
  - ✅ **Type-Safe Translations** - TypeScript autocomplete for all message keys
8
- - ✅ **Locale Persistence** - Locale persists across page reloads via localStorage (`SvelteI18nProvider`)
8
+ - ✅ **Host-Owned Locale** - The host passes the locale in; nothing is read from storage. Persisting to localStorage and reloading on change are opt-in (`SvelteI18nProvider`)
9
+ - ✅ **Locale Negotiation** - Any BCP 47 or POSIX tag resolves by language: `es-MX` and `es_ES` reach Spanish, `ar-EG` reaches Arabic
9
10
  - ✅ **Framework Agnostic** - Core provider works with any JavaScript framework
10
11
  - ✅ **Svelte Integration** - Simple `$derived` pattern for Svelte 5 components
11
12
  - ✅ **Web Component Compatible** - Works within Shadow DOM boundaries
@@ -13,7 +14,7 @@ Lightweight, type-safe internationalization (i18n) package for the PIE-QTI playe
13
14
  - ✅ **On-Demand Loading** - Load additional locales asynchronously
14
15
  - ✅ **Built-in Formatting** - Number and date formatting via `Intl` APIs
15
16
  - ✅ **Custom Translations** - Override or extend framework translations
16
- - ✅ **8 Languages Supported** - en-US (source locale), ar-SA, es-ES, fr-FR, nl-NL, ro-RO, th-TH, zh-CN
17
+ - ✅ **8 Languages Supported** - en (source locale), ar, es, fr, nl, ro, th, zh-Hans
17
18
 
18
19
  ## Installation
19
20
 
@@ -31,9 +32,9 @@ import { DefaultI18nProvider } from '@pie-qti/i18n';
31
32
  // Create provider with default locale
32
33
  const i18n = new DefaultI18nProvider('en-US');
33
34
 
34
- // Optional: Load additional locales
35
- await i18n.loadLocale('es-ES');
36
- await i18n.loadLocale('fr-FR');
35
+ // Optional: Load additional locales (any tag for the language works)
36
+ await i18n.loadLocale('es-MX');
37
+ await i18n.loadLocale('fr');
37
38
  ```
38
39
 
39
40
  ### 2. Use in Components (Svelte 5)
@@ -48,7 +49,7 @@ interface Props {
48
49
 
49
50
  let { i18n }: Props = $props();
50
51
 
51
- // Simple pattern - locale changes trigger page refresh
52
+ // Recomputed whenever the i18n prop changes
52
53
  const translations = $derived({
53
54
  submit: i18n?.t('common.submit') ?? 'Submit',
54
55
  cancel: i18n?.t('common.cancel') ?? 'Cancel'
@@ -59,7 +60,7 @@ const translations = $derived({
59
60
  <button>{translations.cancel}</button>
60
61
  ```
61
62
 
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
+ **Note:** `$derived` recomputes when the `i18n` prop changes. A `setLocale()` on the same provider object is not tracked; the host re-renders, passes a new provider or `withLocale()` view, or opts into reload (below).
63
64
 
64
65
  ### 3. Switch Locales
65
66
 
@@ -73,18 +74,27 @@ The two providers behave differently:
73
74
  i18n.setLocale('es-ES');
74
75
  ```
75
76
 
76
- - `SvelteI18nProvider.setLocale()` stores the locale in localStorage and triggers a page reload, so
77
- every component picks up the new locale on the fresh page.
77
+ - `SvelteI18nProvider.setLocale()` loads the catalog the locale negotiates to, then switches. It
78
+ persists and reloads only when the host opts in:
78
79
 
79
80
  ```typescript
80
- // Switch to Spanish (persists to localStorage, then reloads the page)
81
- await i18n.setLocale('es-ES');
81
+ import { createDefaultSvelteI18nProvider, DEFAULT_LOCALE_STORAGE_KEY } from '@pie-qti/i18n';
82
+
83
+ // The host reads its own stored value; the provider never reads storage
84
+ const saved = localStorage.getItem(DEFAULT_LOCALE_STORAGE_KEY) ?? 'en-US';
85
+ const i18n = await createDefaultSvelteI18nProvider(saved, undefined, {
86
+ persistLocale: true, // write the locale to localStorage on setLocale()
87
+ reloadOnLocaleChange: true, // reload the page after setLocale()
88
+ // storageKey: 'my-app-locale', // defaults to 'pie-qti-locale'
89
+ });
82
90
 
83
- // On next page load, i18n will automatically use 'es-ES'
91
+ await i18n.setLocale('es-ES'); // persists, then reloads
84
92
  ```
85
93
 
86
- To render a specific player or element in another locale without reloading, use the
87
- `withLocale(locale)` view (available on providers that support it) instead of `setLocale()`.
94
+ To render a specific player or element in another locale without touching the shared provider, use
95
+ the `withLocale(locale)` view instead of `setLocale()`. When that locale's catalog is not loaded yet,
96
+ the view renders English and carries a `ready` promise that settles once the catalog arrives; the
97
+ player custom elements re-render on it.
88
98
 
89
99
  ## API Reference
90
100
 
@@ -103,6 +113,7 @@ interface I18nProvider {
103
113
  plural?(key: string, options: { count: number; [key: string]: any }): string;
104
114
  getDirection?(): 'ltr' | 'rtl';
105
115
  withLocale?(locale: string): I18nProvider;
116
+ readonly ready?: Promise<void>; // set on a withLocale() view still loading its catalog
106
117
  formatNumber?(value: number, options?: Intl.NumberFormatOptions): string;
107
118
  formatDate?(date: Date, options?: Intl.DateTimeFormatOptions): string;
108
119
  }
@@ -126,11 +137,11 @@ const customMessages = {
126
137
  };
127
138
  const i18n = new DefaultI18nProvider('en-US', customMessages);
128
139
 
129
- // Load additional locales
140
+ // Load additional locales; resolves without loading for a language with no catalog
130
141
  await i18n.loadLocale('es-ES');
131
142
 
132
- // Switch locales
133
- await i18n.setLocale('es-ES');
143
+ // Switch locales (synchronous)
144
+ i18n.setLocale('es-ES');
134
145
 
135
146
  // Translate
136
147
  const text = i18n.t('common.submit');
@@ -144,34 +155,59 @@ Svelte-specific wrapper that extends `I18nProvider`:
144
155
  ```typescript
145
156
  import { createDefaultSvelteI18nProvider } from '@pie-qti/i18n';
146
157
 
147
- // Create Svelte provider
158
+ // Create Svelte provider; the locale's catalog is loaded before it resolves
148
159
  const i18n = await createDefaultSvelteI18nProvider('en-US');
149
160
 
150
161
  // Same API as I18nProvider
151
162
  const text = i18n.t('common.submit');
152
- await i18n.setLocale('es-ES'); // Persists to localStorage and triggers a page reload
163
+ await i18n.setLocale('es-ES'); // Loads and switches; no persistence or reload unless opted in
153
164
  ```
154
165
 
155
166
  ### Supported Locales
156
167
 
157
- The framework currently includes 8 locales:
158
-
159
- | Locale Code | Language | Status |
160
- |-------------|---------------------------|-------------------------------|
161
- | `en-US` | English (United States) | ✅ Complete (source locale) |
162
- | `ar-SA` | Arabic (Saudi Arabia) | ✅ Complete |
163
- | `es-ES` | Spanish (Spain) | ✅ Complete |
164
- | `fr-FR` | French (France) | ✅ Complete |
165
- | `nl-NL` | Dutch (Netherlands) | ✅ Complete |
166
- | `ro-RO` | Romanian (Romania) | ✅ Complete |
167
- | `th-TH` | Thai (Thailand) | ✅ Complete |
168
- | `zh-CN` | Chinese (Simplified) | ✅ Complete |
169
-
170
- "Complete" means every en-US key exists in the locale (verified by the translation coverage
168
+ The framework currently includes 8 catalogs, keyed by language (and by script for Chinese):
169
+
170
+ | Catalog | Language | Served tags (examples) | Status |
171
+ |-----------|-----------------------|--------------------------------------|-----------------------------|
172
+ | `en` | English | `en`, `en-US`, `en-GB` | ✅ Complete (source locale) |
173
+ | `ar` | Arabic | `ar`, `ar-SA`, `ar-EG`, `ar_SA` | ✅ Complete |
174
+ | `es` | Spanish | `es`, `es-ES`, `es-MX`, `es-419` | ✅ Complete |
175
+ | `fr` | French | `fr`, `fr-FR`, `fr-CA` | ✅ Complete |
176
+ | `nl` | Dutch | `nl`, `nl-NL`, `nl-BE` | ✅ Complete |
177
+ | `ro` | Romanian | `ro`, `ro-RO` | ✅ Complete |
178
+ | `th` | Thai | `th`, `th-TH` | ✅ Complete |
179
+ | `zh-Hans` | Chinese (Simplified) | `zh`, `zh-CN`, `zh-SG`, `zh-Hans` | ✅ Complete |
180
+
181
+ A tag walks its RFC 4647 lookup sequence (`es-MX`, then `es`), with the language's CLDR likely script
182
+ inserted before the bare language, so `zh-CN` reaches `zh-Hans`. A catalog reached by widening must
183
+ share the request's script: `zh-TW`, `zh-HK` and `zh-Hant` do not get the Simplified catalog and
184
+ render in English. Any key missing from the resolved catalog falls back to English.
185
+ `resolveFrameworkLocale(tag)` answers which catalog serves a tag. The old region-qualified codes
186
+ (`es-ES`, `zh-CN`, …) remain valid `FrameworkLocaleCode` inputs.
187
+
188
+ "Complete" means every English key exists in the locale (verified by the translation coverage
171
189
  checker below). Values that still match English are reported by the checker as *untranslated*
172
190
  rather than missing.
173
191
 
174
- **Note:** Additional locales can be provided via custom translations (see below).
192
+ ### Numbers and dates
193
+
194
+ `formatNumber` and `formatDate` do not take the runtime's defaults, which follow whatever CLDR its
195
+ ICU ships. Digits come from a table pinned to CLDR 48 and the calendar is Gregorian:
196
+
197
+ ```typescript
198
+ new DefaultI18nProvider('ar').formatNumber(1234.5); // '1,234.5'
199
+ new DefaultI18nProvider('ar-EG').formatNumber(1234.5); // '١٬٢٣٤٫٥'
200
+ new DefaultI18nProvider('ar-MA').formatNumber(1234.5); // '1.234,5'
201
+ new DefaultI18nProvider('fa-IR').formatDate(date); // Gregorian year, Extended Arabic-Indic digits
202
+ ```
203
+
204
+ A host that wants other digits or a local calendar sets them on the locale: `ar-SA-u-nu-latn`,
205
+ `fa-IR-u-ca-persian`. Catalog lookup and the `lang` attribute ignore the extension. Numbers passed
206
+ to `t()` and `plural()` are formatted the same way, so `{count}` follows the locale.
207
+ `formattingLocale(tag)` and `numberingSystemFor(tag)` expose the resolution.
208
+
209
+ **Note:** Additional locales can be provided via custom translations (see below). Custom messages are
210
+ matched along the same lookup sequence, so a `de` entry serves `de-AT`.
175
211
 
176
212
  ## Message Keys
177
213
 
@@ -196,7 +232,7 @@ $t('invalid.key')
196
232
  - `assessment.*` - Assessment player UI
197
233
  - `accessibility.*` - ARIA labels and screen reader text
198
234
 
199
- See [en-US.ts](./src/locales/en-US.ts) for the complete list of available keys.
235
+ See [en.ts](./src/locales/en.ts) for the complete list of available keys.
200
236
 
201
237
  ## Custom Translations
202
238
 
@@ -294,14 +330,14 @@ let { i18n = $bindable() }: Props = $props();
294
330
  const t = $derived((key: string, fallback: string) => i18n?.t(key) ?? fallback);
295
331
  ```
296
332
 
297
- **Note:** No manual subscriptions or reactivity tracking needed. Locale changes trigger a page reload, so components always render with the correct locale.
333
+ **Note:** No manual subscriptions needed. Components re-render when the host passes a new provider or view; hosts that change the locale in place opt into reload.
298
334
 
299
335
  ## Bundle Size
300
336
 
301
337
  | Component | Size (gzipped) |
302
338
  |-------------------------------|----------------|
303
339
  | Core i18n logic | ~2 KB |
304
- | English locale (en-US) | ~8 KB |
340
+ | English catalog (en) | ~8 KB |
305
341
  | Additional locale (on-demand) | ~8 KB each |
306
342
  | **Total (default)** | **~10 KB** |
307
343
 
@@ -312,7 +348,7 @@ For detailed guides, see the `docs/` directory:
312
348
  - **[Integration Guide](./docs/INTEGRATION_GUIDE.md)** - Complete guide for adding i18n to components
313
349
  - **[Component UI Patterns](./docs/INTEGRATION_GUIDE.md#component-ui-patterns)** - Svelte 5 + DaisyUI patterns and examples
314
350
  - **[Advanced Features](./docs/ADVANCED_FEATURES.md)** - Pluralization, number & date formatting
315
- - **[Message Keys](./src/locales/en-US.ts)** - All available translation keys and namespaces
351
+ - **[Message Keys](./src/locales/en.ts)** - All available translation keys and namespaces
316
352
 
317
353
  ## Development
318
354
 
@@ -321,7 +357,7 @@ For detailed guides, see the `docs/` directory:
321
357
  1. Add to English locale:
322
358
 
323
359
  ```typescript
324
- // src/locales/en-US.ts
360
+ // src/locales/en.ts
325
361
  export default {
326
362
  myFeature: {
327
363
  newMessage: 'My new message',
@@ -348,12 +384,12 @@ The package includes an automated translation coverage checker that ensures all
348
384
  bun run check-translations
349
385
 
350
386
  # Check specific locale
351
- bun run scripts/check-translations.ts --locale nl-NL
387
+ bun run scripts/check-translations.ts --locale=nl
352
388
  ```
353
389
 
354
390
  The checker:
355
391
 
356
- - ✅ **Automatically discovers** all keys from en-US (no hardcoded lists)
392
+ - ✅ **Automatically discovers** all keys from en (no hardcoded lists)
357
393
  - ✅ **Automatically detects** all locale files (no configuration)
358
394
  - ✅ **Reports missing keys** in other locales
359
395
  - ✅ **Detects obsolete keys** that should be removed
@@ -370,33 +406,46 @@ and options.
370
406
 
371
407
  ### Hardcoded String Scanner
372
408
 
373
- The package includes a scanner that detects hardcoded English strings in component files that should use i18n:
409
+ The scanner parses Svelte templates with the Svelte compiler and reports learner-visible strings that bypass the catalog: template text, and `aria-label`, `title` and `placeholder` values on DOM elements that are static text or a template literal. Script literals, component props and test directories are out of scope. A finding names the catalog key when en already carries the string.
374
410
 
375
411
  ```bash
376
- # Scan default components package
412
+ # Scan every package (advisory)
377
413
  bun run scan-hardcoded
378
414
 
415
+ # Exit 1 on any finding; `bun run check:i18n` and CI run it this way
416
+ bun run scan-hardcoded --strict
417
+
379
418
  # Scan a custom path
380
419
  bun run scan-hardcoded --path=../custom-components
381
420
  ```
382
421
 
383
- The scanner:
422
+ Put `<!-- i18n-ignore -->` before an element or text node that no learner reads in their own language, such as a code sample; the node and its subtree are skipped.
384
423
 
385
- - ✅ **Detects hardcoded strings** that match translation values in en-US
386
- - ✅ **Suggests the correct i18n key** to use for each match
387
- - ✅ **Scans .svelte and .ts files** recursively
388
- - ✅ **Provides exact replacement code** for each hardcoded string
424
+ ```text
425
+ packages/default-components: 1 finding(s)
426
+ packages/default-components/src/plugins/order/OrderInteraction.svelte:212 text"Order confirmed" → t('interactions.order.orderConfirmed')
427
+ ```
389
428
 
390
- **Example output:**
429
+ ### Physical-Direction CSS Check
391
430
 
392
- ```text
393
- 📄 plugins/graphic-order/GraphicOrderInteraction.svelte (1 match)
394
- ────────────────────────────────────────────────────────────────
395
- Line 138: <h3>Order (drag to reorder)</h3>
396
- Use: i18n?.t('interactions.graphicOrder.orderHeading') ?? 'Order (drag to reorder)'
431
+ `bun run check-physical-css` reports CSS that does not mirror under `dir="rtl"`: `margin-left`, `right: 0`, `text-align: left`, `border-top-left-radius`, and Tailwind utilities such as `ml-2`, `right-2` and `text-left` in `class` attributes. Use the logical form (`margin-inline-start`, `inset-inline-end`, `text-align: start`, `ms-2`, `end-2`, `text-start`). It runs last in `check:i18n` and exits 1 on any finding.
432
+
433
+ Graphic and spatial interactions are exempt, since their coordinates are image space. For CSS physical by definition, such as the QTI `qti-align-left` class, put an `i18n-physical` comment on the line or the line above.
434
+
435
+ ### Pseudo-Locales
436
+
437
+ `pseudoLocalize(en)` turns a catalog into accented, lengthened, bracketed English with the same keys and placeholders. Register it under `PSEUDO_LOCALE_RTL` (`ar-XB`) to see untranslated strings, truncation and clipping in a right-to-left layout, or under `PSEUDO_LOCALE_EXPANDED` (`en-XA`) for expansion alone:
438
+
439
+ ```typescript
440
+ import { DefaultI18nProvider, PSEUDO_LOCALE_RTL, pseudoLocalize } from '@pie-qti/i18n';
441
+ import en from '@pie-qti/i18n/locales/en.js';
442
+
443
+ const i18n = new DefaultI18nProvider(PSEUDO_LOCALE_RTL, { [PSEUDO_LOCALE_RTL]: pseudoLocalize(en) });
444
+ await i18n.loadLocale(PSEUDO_LOCALE_RTL);
445
+ i18n.t('common.close'); // '[Çĺóšé ~~]'
397
446
  ```
398
447
 
399
- This tool helps maintain consistency by ensuring all user-facing strings use the i18n system.
448
+ The demo's web-component routes accept `?locale=ar-XB`, which `apps/demo/tests/playwright/rtl-matrix.pw.ts` runs alongside `ar`.
400
449
 
401
450
  ### Running Tests
402
451
 
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Default I18n provider implementation
3
+ *
4
+ * This is the framework's default implementation of the I18nProvider interface.
5
+ * It uses standard dynamic imports for lazy locale loading and provides simple
6
+ * interpolation and pluralization support.
7
+ */
8
+ import type { I18nProvider, InterpolationValues, PluralOptions } from './I18nProvider.js';
9
+ import type { LocaleCode, MessageKey, LocaleMessages } from './types.js';
10
+ export declare class DefaultI18nProvider implements I18nProvider {
11
+ /** Shared across instances: constructing Intl.PluralRules is not cheap */
12
+ private static pluralRules;
13
+ private currentLocale;
14
+ private messages;
15
+ private customMessages;
16
+ private loadedLocales;
17
+ private pendingLoads;
18
+ /**
19
+ * Settles once the catalog for this provider's locale is loaded. Set only on
20
+ * a `withLocale()` view created before that catalog was resident; the view
21
+ * starts the load itself. Never rejects: a failed load is logged and the view
22
+ * keeps rendering through the English fallback.
23
+ */
24
+ ready?: Promise<void>;
25
+ /**
26
+ * @param locale - Active locale; any BCP 47 or POSIX tag. The host owns this
27
+ * value: the provider reads no storage and persists nothing.
28
+ * @param customMessages - Host translations by locale tag, consulted before
29
+ * the framework catalogs.
30
+ */
31
+ constructor(locale?: LocaleCode, customMessages?: Record<string, LocaleMessages>);
32
+ /**
33
+ * Load the framework catalog that serves a locale tag.
34
+ *
35
+ * The tag is negotiated (`es-MX` loads `es`, `zh-CN` loads `zh-Hans`). A tag
36
+ * no framework catalog serves resolves without loading anything: it renders
37
+ * from custom messages and the English fallback. Rejects only when a catalog
38
+ * module fails to load.
39
+ */
40
+ loadLocale(locale: LocaleCode): Promise<void>;
41
+ /**
42
+ * Whether every catalog a locale needs is resident: true for a tag no
43
+ * framework catalog serves, since there is nothing to load.
44
+ */
45
+ isLocaleLoaded(locale: LocaleCode): boolean;
46
+ /**
47
+ * Set current locale
48
+ * For framework locales, loadLocale() should be called first.
49
+ * For custom locales, translations should be provided via customMessages.
50
+ */
51
+ setLocale(locale: string): void;
52
+ /**
53
+ * Get current locale
54
+ */
55
+ getLocale(): string;
56
+ /**
57
+ * Translate message key with optional default and/or interpolation
58
+ * @example t('upload.label') => "Upload a file"
59
+ * @example t('upload.label', 'Upload') => translated or "Upload" if missing
60
+ * @example t('upload.selected', { name: 'file.pdf' }) => "Selected: file.pdf"
61
+ */
62
+ t(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string;
63
+ /**
64
+ * Pluralization support
65
+ *
66
+ * The plural category comes from `Intl.PluralRules` for the active locale, so
67
+ * locales with more than two forms resolve correctly: Arabic selects between
68
+ * zero/one/two/few/many/other, Romanian between one/few/other. A locale whose
69
+ * catalog does not carry the selected category falls back to `.other`.
70
+ *
71
+ * @example plural('plurals.files', { count: 1 }) => "1 file selected"
72
+ * @example plural('plurals.files', { count: 5 }) => "5 files selected"
73
+ */
74
+ plural(key: string, options: PluralOptions): string;
75
+ /**
76
+ * Select the CLDR plural category for a count in the active locale
77
+ *
78
+ * Falls back to the English one/other split if the locale tag is not one
79
+ * `Intl.PluralRules` accepts — a host may set an arbitrary custom locale code.
80
+ */
81
+ private selectPluralCategory;
82
+ /**
83
+ * Writing direction of the current locale
84
+ *
85
+ * @example getDirection() => 'rtl' for ar-SA, 'ltr' for en-US
86
+ */
87
+ getDirection(): 'ltr' | 'rtl';
88
+ /**
89
+ * A view of this provider fixed to another locale
90
+ *
91
+ * Catalogs, loaded-locale bookkeeping and custom messages are shared by
92
+ * reference, so `loadLocale()` through either side is visible to both and no
93
+ * catalog is parsed twice. This is what lets two players on one page render
94
+ * different locales from one provider: the locale is per-view, the catalogs
95
+ * are per-provider.
96
+ *
97
+ * When the catalog its locale negotiates to is not resident, the view loads
98
+ * it and `ready` settles when that load does; until then it renders through
99
+ * the English fallback. A view over a resident catalog has no `ready`.
100
+ */
101
+ withLocale(locale: LocaleCode): DefaultI18nProvider;
102
+ /**
103
+ * Format a number in the locale's pinned numbering system
104
+ *
105
+ * @example formatNumber(1234.5) => "1,234.5" for ar, "١٬٢٣٤٫٥" for ar-EG
106
+ */
107
+ formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
108
+ /**
109
+ * Format a date in the locale's pinned numbering system, on the Gregorian
110
+ * calendar unless the locale carries `-u-ca-`
111
+ */
112
+ formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string;
113
+ /**
114
+ * Get nested message by dot notation key
115
+ *
116
+ * Walks the active locale's negotiation sequence, then the English fallback's.
117
+ * At each step custom messages come before the framework catalog, so for
118
+ * `es-MX` the order is custom `es-MX`, custom `es`, framework `es`, custom
119
+ * `en-US`, custom `en`, framework `en`.
120
+ */
121
+ private getMessage;
122
+ private lookupMessage;
123
+ /**
124
+ * Get message from a specific messages object
125
+ *
126
+ * Resolves to a string or nothing. A key that lands on a namespace branch
127
+ * (`t('common')`) or on a plural sub-object (`t('plurals.items')`) is a miss,
128
+ * not a hit: returning the branch would put an object where the caller
129
+ * expects a string, and interpolating one throws.
130
+ */
131
+ private getMessageFromObject;
132
+ /**
133
+ * Add or update custom messages for a locale
134
+ * This allows clients to provide their own translations or override defaults
135
+ */
136
+ addCustomMessages(locale: string, messages: LocaleMessages): void;
137
+ /**
138
+ * Deep merge two objects (for merging translation objects)
139
+ */
140
+ private deepMerge;
141
+ }
142
+ /**
143
+ * Factory function to create a default i18n provider instance
144
+ * @param locale - Initial locale code (default: 'en-US')
145
+ * @param customMessages - Optional custom translations to add or override framework defaults
146
+ * @returns DefaultI18nProvider instance
147
+ */
148
+ export declare function createDefaultI18nProvider(locale?: LocaleCode, customMessages?: Record<string, LocaleMessages>): I18nProvider;
149
+ export type { LocaleCode, MessageKey, InterpolationValues, PluralOptions };