@sonenta/react-i18next 2.1.0 → 2.3.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.
- package/README.md +78 -0
- package/dist/index.cjs +270 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +140 -2
- package/dist/index.d.ts +140 -2
- package/dist/index.js +268 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -13,6 +13,24 @@ import { i18n } from 'i18next';
|
|
|
13
13
|
* the reactive viewport listener (web) — see `provider.tsx`.
|
|
14
14
|
*/
|
|
15
15
|
type Surface = "desktop" | "mobile" | "tablet";
|
|
16
|
+
/**
|
|
17
|
+
* A11y surfaces (#989 / task 994) — SEMANTIC accessibility variants of a key,
|
|
18
|
+
* delivered through the SAME sparse-overlay engine as device surfaces but
|
|
19
|
+
* applied ORTHOGONALLY to the visible text:
|
|
20
|
+
* - `aria_label` → an element's `aria-label` attribute
|
|
21
|
+
* - `alt_text` → an `<img alt>` (+ optional localized image via `$asset`)
|
|
22
|
+
* - `screen_reader` → verbose screen-reader-only (sr-only) text
|
|
23
|
+
* - `plain_language`→ simplified/clear-language (FALC) alternative rendering
|
|
24
|
+
*
|
|
25
|
+
* Unlike a device {@link Surface} (which replaces the visible `t()` value),
|
|
26
|
+
* a11y surfaces are read per-key via `i18n.aria()` / `alt()` / `a11y()` —
|
|
27
|
+
* EXCEPT `plain_language`, which the cognitive `plainLanguage` toggle layers
|
|
28
|
+
* over the visible `t()` output when enabled.
|
|
29
|
+
*/
|
|
30
|
+
type A11ySurface = "aria_label" | "alt_text" | "screen_reader" | "plain_language";
|
|
31
|
+
/** The fixed V1 a11y surface taxonomy (matches the backend `surfaceKinds`
|
|
32
|
+
* `a11y` set). Used to validate config + drive eager overlay loading. */
|
|
33
|
+
declare const A11Y_SURFACES: readonly A11ySurface[];
|
|
16
34
|
/** Min-width (px) thresholds that map a viewport width to a surface. A width
|
|
17
35
|
* `< mobile` → `mobile`; `< tablet` → `tablet`; otherwise `desktop`. Mirrors
|
|
18
36
|
* the common mobile-first breakpoint ladder. */
|
|
@@ -65,6 +83,20 @@ interface LanguageMeta {
|
|
|
65
83
|
/** CLDR plural categories present for this language. */
|
|
66
84
|
plural_categories?: string[];
|
|
67
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* A language PUBLISHED for the active version (task: available-languages) — a
|
|
88
|
+
* {@link LanguageMeta} (enriched from the catalog) plus publish info from the
|
|
89
|
+
* per-version CDN manifest. Returned by `i18n.availableLanguages` /
|
|
90
|
+
* `useAvailableLanguages()`.
|
|
91
|
+
*/
|
|
92
|
+
interface AvailableLanguage extends LanguageMeta {
|
|
93
|
+
/** ISO timestamp this language was published for the active version, when
|
|
94
|
+
* the manifest provides it (optional / forward-compat). Render a
|
|
95
|
+
* "recently added" hint if present; ignore if absent. */
|
|
96
|
+
published_at?: string;
|
|
97
|
+
/** True when this is the project's default locale for the active version. */
|
|
98
|
+
is_default?: boolean;
|
|
99
|
+
}
|
|
68
100
|
interface MissingKeyEvent {
|
|
69
101
|
key: string;
|
|
70
102
|
namespace: Namespace;
|
|
@@ -144,6 +176,14 @@ interface SonentaConfig {
|
|
|
144
176
|
* you supply {@link SonentaConfig.languageCatalog} yourself.
|
|
145
177
|
*/
|
|
146
178
|
disableLanguageCatalog?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Skip the best-effort fetch of the per-version published-languages manifest
|
|
181
|
+
* (`{cdnBase}/p/{project}/{version}/latest/languages.json`, public, no auth)
|
|
182
|
+
* that powers `i18n.availableLanguages` / `useAvailableLanguages()`. When
|
|
183
|
+
* skipped (or on a 404), `availableLanguages` falls back to the configured
|
|
184
|
+
* `defaultLocale` + `fallbackLng`.
|
|
185
|
+
*/
|
|
186
|
+
disableLanguageManifest?: boolean;
|
|
147
187
|
/**
|
|
148
188
|
* Interpolation hooks forwarded to i18next. Currently exposes `format`, the
|
|
149
189
|
* value formatter i18next invokes for `{{value, format}}` placeholders — wire
|
|
@@ -227,6 +267,23 @@ interface SonentaConfig {
|
|
|
227
267
|
* own `useWindowDimensions`. Ignored when `surface` is unset.
|
|
228
268
|
*/
|
|
229
269
|
surfaceBreakpoints?: SurfaceBreakpoints | boolean;
|
|
270
|
+
/**
|
|
271
|
+
* A11y surfaces (#989 / task 994) to eagerly load alongside the base
|
|
272
|
+
* bundles, so `i18n.aria()` / `alt()` / `a11y()` resolve synchronously in
|
|
273
|
+
* render. Each is a sparse `{ns}.{surface}.json` overlay applied
|
|
274
|
+
* ORTHOGONALLY to the visible text (NOT a `t()` replacement). Omit to
|
|
275
|
+
* disable a11y resolution. Include `"plain_language"` to power the
|
|
276
|
+
* {@link SonentaConfig.plainLanguage} toggle.
|
|
277
|
+
*/
|
|
278
|
+
a11ySurfaces?: A11ySurface[];
|
|
279
|
+
/**
|
|
280
|
+
* Start with the cognitive simplified-language ("plain language" / FALC)
|
|
281
|
+
* mode ON — when enabled, `t()` returns the `plain_language` overlay value
|
|
282
|
+
* for keys that have one (else the base text). Toggle at runtime via
|
|
283
|
+
* `i18n.setPlainLanguage(on)`. No effect unless `plain_language` is loaded
|
|
284
|
+
* (it is auto-included when this is `true`, or list it in `a11ySurfaces`).
|
|
285
|
+
*/
|
|
286
|
+
plainLanguage?: boolean;
|
|
230
287
|
/**
|
|
231
288
|
* Deployment environment. Drives where the SDK fetches translations from:
|
|
232
289
|
*
|
|
@@ -342,6 +399,43 @@ interface I18nInstance {
|
|
|
342
399
|
* asset (e.g. an icon/image ref) for the host to render.
|
|
343
400
|
*/
|
|
344
401
|
asset: (key: string, namespace?: Namespace) => AssetRef | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* A11y (#989 / task 994) — the accessible NAME for a key (`aria_label`
|
|
404
|
+
* overlay), falling back to the visible `t(key)` text when no a11y override
|
|
405
|
+
* exists. Spread onto an element as `aria-label`. Requires `aria_label` in
|
|
406
|
+
* {@link SonentaConfig.a11ySurfaces}.
|
|
407
|
+
*/
|
|
408
|
+
aria: (key: string, namespace?: Namespace) => string;
|
|
409
|
+
/**
|
|
410
|
+
* A11y — the image alternative text for a key (`alt_text` overlay), falling
|
|
411
|
+
* back to the visible `t(key)` text. Pair with {@link I18nInstance.a11yAsset}
|
|
412
|
+
* for a localized image. Requires `alt_text` in `a11ySurfaces`.
|
|
413
|
+
*/
|
|
414
|
+
alt: (key: string, namespace?: Namespace) => string;
|
|
415
|
+
/**
|
|
416
|
+
* A11y — resolve an arbitrary a11y `surface` overlay for a key, or
|
|
417
|
+
* `undefined` when no override exists (use for `screen_reader` /
|
|
418
|
+
* `plain_language`, which should be OMITTED rather than fall back to the
|
|
419
|
+
* visible text). `aria` / `alt` are convenience wrappers that fall back.
|
|
420
|
+
*/
|
|
421
|
+
a11y: (key: string, surface: A11ySurface, namespace?: Namespace) => string | undefined;
|
|
422
|
+
/**
|
|
423
|
+
* A11y — the localized-image `$asset` ref carried by a key's `alt_text`
|
|
424
|
+
* overlay, or `undefined`. Lets the host swap the IMAGE per locale, not just
|
|
425
|
+
* its alt text.
|
|
426
|
+
*/
|
|
427
|
+
a11yAsset: (key: string, namespace?: Namespace) => AssetRef | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* A11y — whether the cognitive simplified-language ("plain language") mode is
|
|
430
|
+
* ON. When `true`, `t()` returns the `plain_language` overlay value for keys
|
|
431
|
+
* that have one (else the base text).
|
|
432
|
+
*/
|
|
433
|
+
plainLanguage: boolean;
|
|
434
|
+
/**
|
|
435
|
+
* A11y — toggle simplified-language mode and re-render. Loads the
|
|
436
|
+
* `plain_language` overlays on first enable if not already configured.
|
|
437
|
+
*/
|
|
438
|
+
setPlainLanguage: (on: boolean) => Promise<void>;
|
|
345
439
|
/**
|
|
346
440
|
* Text direction of a locale (defaults to the active locale) — i18next
|
|
347
441
|
* parity. Sourced from the language catalog's `rtl` (variant → base
|
|
@@ -362,6 +456,15 @@ interface I18nInstance {
|
|
|
362
456
|
* parent, …), defaulting to the active locale; `undefined` if unknown.
|
|
363
457
|
*/
|
|
364
458
|
languageMeta: (lng?: Locale) => LanguageMeta | undefined;
|
|
459
|
+
/**
|
|
460
|
+
* The languages PUBLISHED for the active version (from the per-version CDN
|
|
461
|
+
* manifest, enriched with catalog metadata) — drives a runtime language
|
|
462
|
+
* switcher that updates when a new language ships WITHOUT recompiling the
|
|
463
|
+
* app. Falls back to `defaultLocale` + `fallbackLng` when no manifest is
|
|
464
|
+
* available. Refreshed on `reload()`. Prefer the `useAvailableLanguages()`
|
|
465
|
+
* hook in React (reactive).
|
|
466
|
+
*/
|
|
467
|
+
availableLanguages: AvailableLanguage[];
|
|
365
468
|
/**
|
|
366
469
|
* The underlying real `i18next` instance powering this SDK (thin-wrapper,
|
|
367
470
|
* #805). Exposed for react-i18next DROP-IN: pass it to react-i18next's own
|
|
@@ -383,6 +486,22 @@ interface TranslationFunction {
|
|
|
383
486
|
/** Native form: `t('key', { defaultValue, ...interpolation })`. */
|
|
384
487
|
(key: string, options?: TranslationOptions): string;
|
|
385
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* The `t` returned by {@link useTranslation} — a {@link TranslationFunction}
|
|
491
|
+
* augmented with a11y accessors (#989 / task 994) so a host can write
|
|
492
|
+
* `t.aria(key)` / `t.alt(key)` / `t.a11y(key, surface)` right next to `t(key)`.
|
|
493
|
+
* They honor the hook's `defaultNamespace` and delegate to the engine.
|
|
494
|
+
*/
|
|
495
|
+
interface A11yTranslationFunction extends TranslationFunction {
|
|
496
|
+
/** Accessible name for `key` (`aria_label`), falling back to the visible
|
|
497
|
+
* text. Spread onto an element as `aria-label`. */
|
|
498
|
+
aria: (key: string, namespace?: Namespace) => string;
|
|
499
|
+
/** Image alt text for `key` (`alt_text`), falling back to the visible text. */
|
|
500
|
+
alt: (key: string, namespace?: Namespace) => string;
|
|
501
|
+
/** Resolve an arbitrary a11y `surface` overlay for `key`, or `undefined`
|
|
502
|
+
* when no override exists (e.g. `screen_reader` / `plain_language`). */
|
|
503
|
+
a11y: (key: string, surface: A11ySurface, namespace?: Namespace) => string | undefined;
|
|
504
|
+
}
|
|
386
505
|
|
|
387
506
|
interface SonentaProviderProps extends SonentaConfig {
|
|
388
507
|
children: ReactNode;
|
|
@@ -390,7 +509,7 @@ interface SonentaProviderProps extends SonentaConfig {
|
|
|
390
509
|
declare function SonentaProvider({ children, ...config }: SonentaProviderProps): react_jsx_runtime.JSX.Element;
|
|
391
510
|
|
|
392
511
|
interface UseTranslationResult {
|
|
393
|
-
t:
|
|
512
|
+
t: A11yTranslationFunction;
|
|
394
513
|
i18n: I18nInstance;
|
|
395
514
|
}
|
|
396
515
|
/** React hook — returns `{ t, i18n }`. Optional `defaultNamespace` lets you
|
|
@@ -402,6 +521,25 @@ interface UseTranslationResult {
|
|
|
402
521
|
* contribution is keyed to THIS hook instance and dropped on unmount, so
|
|
403
522
|
* navigating away removes its keys automatically. */
|
|
404
523
|
declare function useTranslation(defaultNamespace?: string): UseTranslationResult;
|
|
524
|
+
/**
|
|
525
|
+
* React hook — the languages PUBLISHED for the active version, enriched with
|
|
526
|
+
* catalog metadata (native_name / rtl / …). Drives a runtime language switcher
|
|
527
|
+
* that picks up a newly-published language WITHOUT recompiling the app: the
|
|
528
|
+
* per-version manifest is CDN-served, so the new language appears on the next
|
|
529
|
+
* load (or after `i18n.reload()`). Falls back to `defaultLocale` +
|
|
530
|
+
* `fallbackLng` when no manifest is available.
|
|
531
|
+
*
|
|
532
|
+
* ```tsx
|
|
533
|
+
* const langs = useAvailableLanguages();
|
|
534
|
+
* const { i18n } = useTranslation();
|
|
535
|
+
* return langs.map((l) => (
|
|
536
|
+
* <button key={l.code} onClick={() => i18n.setLocale(l.code)}>
|
|
537
|
+
* {l.native_name ?? l.code}{l.is_default ? " ★" : ""}
|
|
538
|
+
* </button>
|
|
539
|
+
* ));
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare function useAvailableLanguages(): AvailableLanguage[];
|
|
405
543
|
|
|
406
544
|
interface TransProps {
|
|
407
545
|
/** The translation key (optionally `ns:key`). */
|
|
@@ -537,4 +675,4 @@ declare class KeyRegistry {
|
|
|
537
675
|
/** Process-wide singleton — there is exactly one on-screen registry. */
|
|
538
676
|
declare const keyRegistry: KeyRegistry;
|
|
539
677
|
|
|
540
|
-
export { type AssetRef, DEFAULT_SURFACE_BREAKPOINTS, type DeclaredKey, type I18nInstance, type LanguageMeta, type Locale, type MissingHandlerMode, type MissingKeyEvent, type Namespace, type SonentaConfig, type SonentaPlugin, type SonentaPluginContext, SonentaProvider, type Surface, type SurfaceBreakpoints, Trans, type TranslationFunction, type TranslationOptions, type Transport, type SonentaConfig as VerbumiaConfig, type SonentaPlugin as VerbumiaPlugin, type SonentaPluginContext as VerbumiaPluginContext, SonentaProvider as VerbumiaProvider, defaultTransport, getI18n, getI18nSafe, keyRegistry, logTransport, surfaceForWidth, t, useTranslation };
|
|
678
|
+
export { A11Y_SURFACES, type A11ySurface, type A11yTranslationFunction, type AssetRef, type AvailableLanguage, DEFAULT_SURFACE_BREAKPOINTS, type DeclaredKey, type I18nInstance, type LanguageMeta, type Locale, type MissingHandlerMode, type MissingKeyEvent, type Namespace, type SonentaConfig, type SonentaPlugin, type SonentaPluginContext, SonentaProvider, type Surface, type SurfaceBreakpoints, Trans, type TranslationFunction, type TranslationOptions, type Transport, type SonentaConfig as VerbumiaConfig, type SonentaPlugin as VerbumiaPlugin, type SonentaPluginContext as VerbumiaPluginContext, SonentaProvider as VerbumiaProvider, defaultTransport, getI18n, getI18nSafe, keyRegistry, logTransport, surfaceForWidth, t, useAvailableLanguages, useTranslation };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,24 @@ import { i18n } from 'i18next';
|
|
|
13
13
|
* the reactive viewport listener (web) — see `provider.tsx`.
|
|
14
14
|
*/
|
|
15
15
|
type Surface = "desktop" | "mobile" | "tablet";
|
|
16
|
+
/**
|
|
17
|
+
* A11y surfaces (#989 / task 994) — SEMANTIC accessibility variants of a key,
|
|
18
|
+
* delivered through the SAME sparse-overlay engine as device surfaces but
|
|
19
|
+
* applied ORTHOGONALLY to the visible text:
|
|
20
|
+
* - `aria_label` → an element's `aria-label` attribute
|
|
21
|
+
* - `alt_text` → an `<img alt>` (+ optional localized image via `$asset`)
|
|
22
|
+
* - `screen_reader` → verbose screen-reader-only (sr-only) text
|
|
23
|
+
* - `plain_language`→ simplified/clear-language (FALC) alternative rendering
|
|
24
|
+
*
|
|
25
|
+
* Unlike a device {@link Surface} (which replaces the visible `t()` value),
|
|
26
|
+
* a11y surfaces are read per-key via `i18n.aria()` / `alt()` / `a11y()` —
|
|
27
|
+
* EXCEPT `plain_language`, which the cognitive `plainLanguage` toggle layers
|
|
28
|
+
* over the visible `t()` output when enabled.
|
|
29
|
+
*/
|
|
30
|
+
type A11ySurface = "aria_label" | "alt_text" | "screen_reader" | "plain_language";
|
|
31
|
+
/** The fixed V1 a11y surface taxonomy (matches the backend `surfaceKinds`
|
|
32
|
+
* `a11y` set). Used to validate config + drive eager overlay loading. */
|
|
33
|
+
declare const A11Y_SURFACES: readonly A11ySurface[];
|
|
16
34
|
/** Min-width (px) thresholds that map a viewport width to a surface. A width
|
|
17
35
|
* `< mobile` → `mobile`; `< tablet` → `tablet`; otherwise `desktop`. Mirrors
|
|
18
36
|
* the common mobile-first breakpoint ladder. */
|
|
@@ -65,6 +83,20 @@ interface LanguageMeta {
|
|
|
65
83
|
/** CLDR plural categories present for this language. */
|
|
66
84
|
plural_categories?: string[];
|
|
67
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* A language PUBLISHED for the active version (task: available-languages) — a
|
|
88
|
+
* {@link LanguageMeta} (enriched from the catalog) plus publish info from the
|
|
89
|
+
* per-version CDN manifest. Returned by `i18n.availableLanguages` /
|
|
90
|
+
* `useAvailableLanguages()`.
|
|
91
|
+
*/
|
|
92
|
+
interface AvailableLanguage extends LanguageMeta {
|
|
93
|
+
/** ISO timestamp this language was published for the active version, when
|
|
94
|
+
* the manifest provides it (optional / forward-compat). Render a
|
|
95
|
+
* "recently added" hint if present; ignore if absent. */
|
|
96
|
+
published_at?: string;
|
|
97
|
+
/** True when this is the project's default locale for the active version. */
|
|
98
|
+
is_default?: boolean;
|
|
99
|
+
}
|
|
68
100
|
interface MissingKeyEvent {
|
|
69
101
|
key: string;
|
|
70
102
|
namespace: Namespace;
|
|
@@ -144,6 +176,14 @@ interface SonentaConfig {
|
|
|
144
176
|
* you supply {@link SonentaConfig.languageCatalog} yourself.
|
|
145
177
|
*/
|
|
146
178
|
disableLanguageCatalog?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Skip the best-effort fetch of the per-version published-languages manifest
|
|
181
|
+
* (`{cdnBase}/p/{project}/{version}/latest/languages.json`, public, no auth)
|
|
182
|
+
* that powers `i18n.availableLanguages` / `useAvailableLanguages()`. When
|
|
183
|
+
* skipped (or on a 404), `availableLanguages` falls back to the configured
|
|
184
|
+
* `defaultLocale` + `fallbackLng`.
|
|
185
|
+
*/
|
|
186
|
+
disableLanguageManifest?: boolean;
|
|
147
187
|
/**
|
|
148
188
|
* Interpolation hooks forwarded to i18next. Currently exposes `format`, the
|
|
149
189
|
* value formatter i18next invokes for `{{value, format}}` placeholders — wire
|
|
@@ -227,6 +267,23 @@ interface SonentaConfig {
|
|
|
227
267
|
* own `useWindowDimensions`. Ignored when `surface` is unset.
|
|
228
268
|
*/
|
|
229
269
|
surfaceBreakpoints?: SurfaceBreakpoints | boolean;
|
|
270
|
+
/**
|
|
271
|
+
* A11y surfaces (#989 / task 994) to eagerly load alongside the base
|
|
272
|
+
* bundles, so `i18n.aria()` / `alt()` / `a11y()` resolve synchronously in
|
|
273
|
+
* render. Each is a sparse `{ns}.{surface}.json` overlay applied
|
|
274
|
+
* ORTHOGONALLY to the visible text (NOT a `t()` replacement). Omit to
|
|
275
|
+
* disable a11y resolution. Include `"plain_language"` to power the
|
|
276
|
+
* {@link SonentaConfig.plainLanguage} toggle.
|
|
277
|
+
*/
|
|
278
|
+
a11ySurfaces?: A11ySurface[];
|
|
279
|
+
/**
|
|
280
|
+
* Start with the cognitive simplified-language ("plain language" / FALC)
|
|
281
|
+
* mode ON — when enabled, `t()` returns the `plain_language` overlay value
|
|
282
|
+
* for keys that have one (else the base text). Toggle at runtime via
|
|
283
|
+
* `i18n.setPlainLanguage(on)`. No effect unless `plain_language` is loaded
|
|
284
|
+
* (it is auto-included when this is `true`, or list it in `a11ySurfaces`).
|
|
285
|
+
*/
|
|
286
|
+
plainLanguage?: boolean;
|
|
230
287
|
/**
|
|
231
288
|
* Deployment environment. Drives where the SDK fetches translations from:
|
|
232
289
|
*
|
|
@@ -342,6 +399,43 @@ interface I18nInstance {
|
|
|
342
399
|
* asset (e.g. an icon/image ref) for the host to render.
|
|
343
400
|
*/
|
|
344
401
|
asset: (key: string, namespace?: Namespace) => AssetRef | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* A11y (#989 / task 994) — the accessible NAME for a key (`aria_label`
|
|
404
|
+
* overlay), falling back to the visible `t(key)` text when no a11y override
|
|
405
|
+
* exists. Spread onto an element as `aria-label`. Requires `aria_label` in
|
|
406
|
+
* {@link SonentaConfig.a11ySurfaces}.
|
|
407
|
+
*/
|
|
408
|
+
aria: (key: string, namespace?: Namespace) => string;
|
|
409
|
+
/**
|
|
410
|
+
* A11y — the image alternative text for a key (`alt_text` overlay), falling
|
|
411
|
+
* back to the visible `t(key)` text. Pair with {@link I18nInstance.a11yAsset}
|
|
412
|
+
* for a localized image. Requires `alt_text` in `a11ySurfaces`.
|
|
413
|
+
*/
|
|
414
|
+
alt: (key: string, namespace?: Namespace) => string;
|
|
415
|
+
/**
|
|
416
|
+
* A11y — resolve an arbitrary a11y `surface` overlay for a key, or
|
|
417
|
+
* `undefined` when no override exists (use for `screen_reader` /
|
|
418
|
+
* `plain_language`, which should be OMITTED rather than fall back to the
|
|
419
|
+
* visible text). `aria` / `alt` are convenience wrappers that fall back.
|
|
420
|
+
*/
|
|
421
|
+
a11y: (key: string, surface: A11ySurface, namespace?: Namespace) => string | undefined;
|
|
422
|
+
/**
|
|
423
|
+
* A11y — the localized-image `$asset` ref carried by a key's `alt_text`
|
|
424
|
+
* overlay, or `undefined`. Lets the host swap the IMAGE per locale, not just
|
|
425
|
+
* its alt text.
|
|
426
|
+
*/
|
|
427
|
+
a11yAsset: (key: string, namespace?: Namespace) => AssetRef | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* A11y — whether the cognitive simplified-language ("plain language") mode is
|
|
430
|
+
* ON. When `true`, `t()` returns the `plain_language` overlay value for keys
|
|
431
|
+
* that have one (else the base text).
|
|
432
|
+
*/
|
|
433
|
+
plainLanguage: boolean;
|
|
434
|
+
/**
|
|
435
|
+
* A11y — toggle simplified-language mode and re-render. Loads the
|
|
436
|
+
* `plain_language` overlays on first enable if not already configured.
|
|
437
|
+
*/
|
|
438
|
+
setPlainLanguage: (on: boolean) => Promise<void>;
|
|
345
439
|
/**
|
|
346
440
|
* Text direction of a locale (defaults to the active locale) — i18next
|
|
347
441
|
* parity. Sourced from the language catalog's `rtl` (variant → base
|
|
@@ -362,6 +456,15 @@ interface I18nInstance {
|
|
|
362
456
|
* parent, …), defaulting to the active locale; `undefined` if unknown.
|
|
363
457
|
*/
|
|
364
458
|
languageMeta: (lng?: Locale) => LanguageMeta | undefined;
|
|
459
|
+
/**
|
|
460
|
+
* The languages PUBLISHED for the active version (from the per-version CDN
|
|
461
|
+
* manifest, enriched with catalog metadata) — drives a runtime language
|
|
462
|
+
* switcher that updates when a new language ships WITHOUT recompiling the
|
|
463
|
+
* app. Falls back to `defaultLocale` + `fallbackLng` when no manifest is
|
|
464
|
+
* available. Refreshed on `reload()`. Prefer the `useAvailableLanguages()`
|
|
465
|
+
* hook in React (reactive).
|
|
466
|
+
*/
|
|
467
|
+
availableLanguages: AvailableLanguage[];
|
|
365
468
|
/**
|
|
366
469
|
* The underlying real `i18next` instance powering this SDK (thin-wrapper,
|
|
367
470
|
* #805). Exposed for react-i18next DROP-IN: pass it to react-i18next's own
|
|
@@ -383,6 +486,22 @@ interface TranslationFunction {
|
|
|
383
486
|
/** Native form: `t('key', { defaultValue, ...interpolation })`. */
|
|
384
487
|
(key: string, options?: TranslationOptions): string;
|
|
385
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* The `t` returned by {@link useTranslation} — a {@link TranslationFunction}
|
|
491
|
+
* augmented with a11y accessors (#989 / task 994) so a host can write
|
|
492
|
+
* `t.aria(key)` / `t.alt(key)` / `t.a11y(key, surface)` right next to `t(key)`.
|
|
493
|
+
* They honor the hook's `defaultNamespace` and delegate to the engine.
|
|
494
|
+
*/
|
|
495
|
+
interface A11yTranslationFunction extends TranslationFunction {
|
|
496
|
+
/** Accessible name for `key` (`aria_label`), falling back to the visible
|
|
497
|
+
* text. Spread onto an element as `aria-label`. */
|
|
498
|
+
aria: (key: string, namespace?: Namespace) => string;
|
|
499
|
+
/** Image alt text for `key` (`alt_text`), falling back to the visible text. */
|
|
500
|
+
alt: (key: string, namespace?: Namespace) => string;
|
|
501
|
+
/** Resolve an arbitrary a11y `surface` overlay for `key`, or `undefined`
|
|
502
|
+
* when no override exists (e.g. `screen_reader` / `plain_language`). */
|
|
503
|
+
a11y: (key: string, surface: A11ySurface, namespace?: Namespace) => string | undefined;
|
|
504
|
+
}
|
|
386
505
|
|
|
387
506
|
interface SonentaProviderProps extends SonentaConfig {
|
|
388
507
|
children: ReactNode;
|
|
@@ -390,7 +509,7 @@ interface SonentaProviderProps extends SonentaConfig {
|
|
|
390
509
|
declare function SonentaProvider({ children, ...config }: SonentaProviderProps): react_jsx_runtime.JSX.Element;
|
|
391
510
|
|
|
392
511
|
interface UseTranslationResult {
|
|
393
|
-
t:
|
|
512
|
+
t: A11yTranslationFunction;
|
|
394
513
|
i18n: I18nInstance;
|
|
395
514
|
}
|
|
396
515
|
/** React hook — returns `{ t, i18n }`. Optional `defaultNamespace` lets you
|
|
@@ -402,6 +521,25 @@ interface UseTranslationResult {
|
|
|
402
521
|
* contribution is keyed to THIS hook instance and dropped on unmount, so
|
|
403
522
|
* navigating away removes its keys automatically. */
|
|
404
523
|
declare function useTranslation(defaultNamespace?: string): UseTranslationResult;
|
|
524
|
+
/**
|
|
525
|
+
* React hook — the languages PUBLISHED for the active version, enriched with
|
|
526
|
+
* catalog metadata (native_name / rtl / …). Drives a runtime language switcher
|
|
527
|
+
* that picks up a newly-published language WITHOUT recompiling the app: the
|
|
528
|
+
* per-version manifest is CDN-served, so the new language appears on the next
|
|
529
|
+
* load (or after `i18n.reload()`). Falls back to `defaultLocale` +
|
|
530
|
+
* `fallbackLng` when no manifest is available.
|
|
531
|
+
*
|
|
532
|
+
* ```tsx
|
|
533
|
+
* const langs = useAvailableLanguages();
|
|
534
|
+
* const { i18n } = useTranslation();
|
|
535
|
+
* return langs.map((l) => (
|
|
536
|
+
* <button key={l.code} onClick={() => i18n.setLocale(l.code)}>
|
|
537
|
+
* {l.native_name ?? l.code}{l.is_default ? " ★" : ""}
|
|
538
|
+
* </button>
|
|
539
|
+
* ));
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare function useAvailableLanguages(): AvailableLanguage[];
|
|
405
543
|
|
|
406
544
|
interface TransProps {
|
|
407
545
|
/** The translation key (optionally `ns:key`). */
|
|
@@ -537,4 +675,4 @@ declare class KeyRegistry {
|
|
|
537
675
|
/** Process-wide singleton — there is exactly one on-screen registry. */
|
|
538
676
|
declare const keyRegistry: KeyRegistry;
|
|
539
677
|
|
|
540
|
-
export { type AssetRef, DEFAULT_SURFACE_BREAKPOINTS, type DeclaredKey, type I18nInstance, type LanguageMeta, type Locale, type MissingHandlerMode, type MissingKeyEvent, type Namespace, type SonentaConfig, type SonentaPlugin, type SonentaPluginContext, SonentaProvider, type Surface, type SurfaceBreakpoints, Trans, type TranslationFunction, type TranslationOptions, type Transport, type SonentaConfig as VerbumiaConfig, type SonentaPlugin as VerbumiaPlugin, type SonentaPluginContext as VerbumiaPluginContext, SonentaProvider as VerbumiaProvider, defaultTransport, getI18n, getI18nSafe, keyRegistry, logTransport, surfaceForWidth, t, useTranslation };
|
|
678
|
+
export { A11Y_SURFACES, type A11ySurface, type A11yTranslationFunction, type AssetRef, type AvailableLanguage, DEFAULT_SURFACE_BREAKPOINTS, type DeclaredKey, type I18nInstance, type LanguageMeta, type Locale, type MissingHandlerMode, type MissingKeyEvent, type Namespace, type SonentaConfig, type SonentaPlugin, type SonentaPluginContext, SonentaProvider, type Surface, type SurfaceBreakpoints, Trans, type TranslationFunction, type TranslationOptions, type Transport, type SonentaConfig as VerbumiaConfig, type SonentaPlugin as VerbumiaPlugin, type SonentaPluginContext as VerbumiaPluginContext, SonentaProvider as VerbumiaProvider, defaultTransport, getI18n, getI18nSafe, keyRegistry, logTransport, surfaceForWidth, t, useAvailableLanguages, useTranslation };
|