@rivinia/i18n 0.5.0 → 0.7.1
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/CHANGELOG.md +137 -0
- package/README.md +849 -125
- package/cli/rivinia-i18n-keys.mjs +402 -2
- package/fesm2022/rivinia-i18n-ui.mjs +366 -0
- package/fesm2022/rivinia-i18n-ui.mjs.map +1 -0
- package/fesm2022/rivinia-i18n.mjs +472 -333
- package/fesm2022/rivinia-i18n.mjs.map +1 -1
- package/package.json +5 -1
- package/types/rivinia-i18n-ui.d.ts +112 -0
- package/types/rivinia-i18n.d.ts +82 -103
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivinia/i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Headless Angular language manager: signals, RTL, SSR-safe loaders, fallback language, missing-key reporting, ICU plurals, typed keys.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -50,6 +50,10 @@
|
|
|
50
50
|
".": {
|
|
51
51
|
"types": "./types/rivinia-i18n.d.ts",
|
|
52
52
|
"default": "./fesm2022/rivinia-i18n.mjs"
|
|
53
|
+
},
|
|
54
|
+
"./ui": {
|
|
55
|
+
"types": "./types/rivinia-i18n-ui.d.ts",
|
|
56
|
+
"default": "./fesm2022/rivinia-i18n-ui.mjs"
|
|
53
57
|
}
|
|
54
58
|
},
|
|
55
59
|
"type": "module",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Direction } from "@rivinia/i18n";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { TemplateRef } from "@angular/core";
|
|
4
|
+
/** The slice of a language entry the toggle needs. Structurally satisfied by
|
|
5
|
+
* `Language` from @rivinia/i18n (which requires `dir`). */
|
|
6
|
+
interface LanguageLike {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly nativeName?: string;
|
|
9
|
+
readonly dir?: Direction;
|
|
10
|
+
readonly locale?: string;
|
|
11
|
+
}
|
|
12
|
+
/** The structural slice of `RiviniaI18n` the toggle drives (D30 shape).
|
|
13
|
+
* `RiviniaI18n` satisfies it with no import from core at runtime. */
|
|
14
|
+
interface RiviniaLanguageManager {
|
|
15
|
+
readonly languages: () => readonly LanguageLike[];
|
|
16
|
+
readonly currentLanguage: () => string;
|
|
17
|
+
readonly loadingState: () => 'idle' | 'loading' | 'error';
|
|
18
|
+
setLanguageAsync(id: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The language toggle: one inner `<button>` that switches to the other language
|
|
22
|
+
* of a two-language manager (or presentational pair). The host is the API; the
|
|
23
|
+
* button owns the name, `lang` and `dir`.
|
|
24
|
+
*/
|
|
25
|
+
export declare class RiviniaLanguageToggle {
|
|
26
|
+
readonly manager: import("@angular/core").InputSignal<RiviniaLanguageManager | undefined>;
|
|
27
|
+
readonly languages: import("@angular/core").InputSignal<readonly LanguageLike[]>;
|
|
28
|
+
readonly current: import("@angular/core").InputSignal<string | undefined>;
|
|
29
|
+
readonly label: import("@angular/core").InputSignal<string | undefined>;
|
|
30
|
+
readonly busy: import("@angular/core").InputSignal<boolean>;
|
|
31
|
+
readonly disabled: import("@angular/core").InputSignal<boolean>;
|
|
32
|
+
/** Replaces the default globe. Rendered as-is, so size it with the icon box. */
|
|
33
|
+
readonly icon: import("@angular/core").InputSignal<TemplateRef<unknown> | null>;
|
|
34
|
+
readonly languageChange: import("@angular/core").OutputEmitterRef<string>;
|
|
35
|
+
readonly template: import("@angular/core").Signal<TemplateRef<any> | undefined>;
|
|
36
|
+
private readonly slot;
|
|
37
|
+
private readonly iconSlot;
|
|
38
|
+
private readonly sourceLanguages;
|
|
39
|
+
readonly languageCount: import("@angular/core").Signal<number>;
|
|
40
|
+
readonly manyLanguages: import("@angular/core").Signal<boolean>;
|
|
41
|
+
private readonly currentId;
|
|
42
|
+
/** The language activating the button switches to; `undefined` when nothing renders. */
|
|
43
|
+
readonly target: import("@angular/core").Signal<LanguageLike | undefined>;
|
|
44
|
+
readonly isBusy: import("@angular/core").Signal<boolean>;
|
|
45
|
+
readonly visibleName: import("@angular/core").Signal<string>;
|
|
46
|
+
readonly accessibleName: import("@angular/core").Signal<string>;
|
|
47
|
+
readonly dataLanguages: import("@angular/core").Signal<"2" | "many" | null>;
|
|
48
|
+
private rendered;
|
|
49
|
+
private renderedIcon;
|
|
50
|
+
private warnedMany;
|
|
51
|
+
private warnedLabel;
|
|
52
|
+
ngAfterViewChecked(): void;
|
|
53
|
+
activate(targetId: string): Promise<void>;
|
|
54
|
+
private warn;
|
|
55
|
+
private renderIcon;
|
|
56
|
+
private renderTrigger;
|
|
57
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaLanguageToggle, never>;
|
|
58
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RiviniaLanguageToggle, "rv-language-toggle", never, {
|
|
59
|
+
"manager": {
|
|
60
|
+
"alias": "manager";
|
|
61
|
+
"required": false;
|
|
62
|
+
"isSignal": true;
|
|
63
|
+
};
|
|
64
|
+
"languages": {
|
|
65
|
+
"alias": "languages";
|
|
66
|
+
"required": false;
|
|
67
|
+
"isSignal": true;
|
|
68
|
+
};
|
|
69
|
+
"current": {
|
|
70
|
+
"alias": "current";
|
|
71
|
+
"required": false;
|
|
72
|
+
"isSignal": true;
|
|
73
|
+
};
|
|
74
|
+
"label": {
|
|
75
|
+
"alias": "label";
|
|
76
|
+
"required": false;
|
|
77
|
+
"isSignal": true;
|
|
78
|
+
};
|
|
79
|
+
"busy": {
|
|
80
|
+
"alias": "busy";
|
|
81
|
+
"required": false;
|
|
82
|
+
"isSignal": true;
|
|
83
|
+
};
|
|
84
|
+
"disabled": {
|
|
85
|
+
"alias": "disabled";
|
|
86
|
+
"required": false;
|
|
87
|
+
"isSignal": true;
|
|
88
|
+
};
|
|
89
|
+
"icon": {
|
|
90
|
+
"alias": "icon";
|
|
91
|
+
"required": false;
|
|
92
|
+
"isSignal": true;
|
|
93
|
+
};
|
|
94
|
+
}, {
|
|
95
|
+
"languageChange": "languageChange";
|
|
96
|
+
}, ["template"], never, true, never>;
|
|
97
|
+
}
|
|
98
|
+
interface RiviniaLanguageTriggerContext {
|
|
99
|
+
$implicit: LanguageLike;
|
|
100
|
+
busy: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Marks the `<ng-template>` rendered inside the button in place of the default
|
|
104
|
+
* name span. The toggle captures it with `contentChild(..., { read: TemplateRef })`
|
|
105
|
+
* and renders it through `ViewContainerRef`, so the template is created only when
|
|
106
|
+
* the button is — and never on the server beyond the same pass.
|
|
107
|
+
*/
|
|
108
|
+
export declare class RiviniaLanguageTrigger {
|
|
109
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaLanguageTrigger, never>;
|
|
110
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RiviniaLanguageTrigger, "[rvLanguageTrigger]", never, {}, {}, never, never, true, never>;
|
|
111
|
+
}
|
|
112
|
+
export type { LanguageLike, RiviniaLanguageManager, RiviniaLanguageTriggerContext };
|
package/types/rivinia-i18n.d.ts
CHANGED
|
@@ -123,7 +123,13 @@ interface MissingParamEvent<T extends string = string> {
|
|
|
123
123
|
*/
|
|
124
124
|
interface RiviniaI18nConfig<T extends string = string> {
|
|
125
125
|
readonly languages: readonly Language<T>[];
|
|
126
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Language used on a first visit (no stored preference, detection off).
|
|
128
|
+
* Defaults to the first entry of `languages`. When provided it must be a
|
|
129
|
+
* non-empty id present in `languages` — anything else throws at construction
|
|
130
|
+
* instead of resolving to an undefined language.
|
|
131
|
+
*/
|
|
132
|
+
readonly defaultLanguage?: T;
|
|
127
133
|
/**
|
|
128
134
|
* Language used when a key is absent from the current dictionary. Must be
|
|
129
135
|
* one of `languages`. The fallback dictionary is loaded silently (it never
|
|
@@ -146,6 +152,13 @@ interface RiviniaI18nConfig<T extends string = string> {
|
|
|
146
152
|
readonly switchStrategy?: SwitchStrategy;
|
|
147
153
|
/** Called when a dictionary load fails. The service still falls back safely. */
|
|
148
154
|
readonly onLoadError?: (language: T, error: unknown) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Log a `console.error` when a dictionary fails to load and no `onLoadError`
|
|
157
|
+
* handler is configured. A failed load leaves every key unresolved, so the
|
|
158
|
+
* page renders raw key names; the warning fires once per language per session.
|
|
159
|
+
* @default isDevMode() && !onLoadError
|
|
160
|
+
*/
|
|
161
|
+
readonly warnOnLoadError?: boolean;
|
|
149
162
|
/**
|
|
150
163
|
* Called when `translate()` cannot resolve a key (absent from the current
|
|
151
164
|
* dictionary, from the fallback dictionary, and with no `defaultValue`).
|
|
@@ -230,7 +243,7 @@ export declare class RiviniaLoadError extends Error {
|
|
|
230
243
|
* ``i18n.translate(`status.${code}` as RegisteredI18nKey)``.
|
|
231
244
|
*/
|
|
232
245
|
interface RiviniaI18nKeyRegistry {}
|
|
233
|
-
/** Every key accepted by `translate()`, `t()` and `
|
|
246
|
+
/** Every key accepted by `translate()`, `t()` and the `rvTranslate` pipe. */
|
|
234
247
|
type RegisteredI18nKey = RiviniaI18nKeyRegistry extends {
|
|
235
248
|
keys: infer K extends string;
|
|
236
249
|
} ? K : string;
|
|
@@ -311,11 +324,7 @@ export declare function formatIcu(template: string, params: TranslateParams, loc
|
|
|
311
324
|
export declare class RiviniaI18n<L extends string = string> {
|
|
312
325
|
private readonly _config;
|
|
313
326
|
private readonly _viewTransition;
|
|
314
|
-
private readonly _storageKey;
|
|
315
|
-
private readonly _storageStrategy;
|
|
316
327
|
private readonly _autoApplyDirection;
|
|
317
|
-
/** Writes reach storage/cookies only after an explicit switch (RIV-17). */
|
|
318
|
-
private readonly _persist;
|
|
319
328
|
/** Validated once; `null` means no fallback chain. */
|
|
320
329
|
private readonly _fallbackId;
|
|
321
330
|
/**
|
|
@@ -327,61 +336,40 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
327
336
|
/** Present only on the server: used for cookie reads + transfer writes. */
|
|
328
337
|
private readonly _request;
|
|
329
338
|
private readonly _transfer;
|
|
339
|
+
private readonly _direction;
|
|
330
340
|
/**
|
|
331
341
|
* Platform facts for loaders, built once: `REQUEST` + `<base href>` on the
|
|
332
342
|
* server, `document.baseURI` in the browser. This is what makes the default
|
|
333
343
|
* loader work under SSR instead of fetching a relative URL Node cannot parse.
|
|
334
344
|
*/
|
|
335
345
|
readonly loaderContext: LoaderContext;
|
|
336
|
-
|
|
346
|
+
/** Declared before the storage collaborator: it reads this during setup. */
|
|
337
347
|
private readonly _languages;
|
|
338
|
-
private readonly _loadedTranslations;
|
|
339
|
-
/**
|
|
340
|
-
* The fallback dictionary, kept separate from `_loadedTranslations` (which
|
|
341
|
-
* always mirrors the VISIBLE language). A signal so `t()`'s computed
|
|
342
|
-
* re-evaluates when the fallback arrives.
|
|
343
|
-
*/
|
|
344
|
-
private readonly _fallbackDict;
|
|
345
348
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* The descriptor still code-splits: the fetch implementation loads only on
|
|
350
|
-
* first resolve.
|
|
349
|
+
* Resolved before the storage collaborator reads it: the explicit
|
|
350
|
+
* `defaultLanguage`, else the first configured language. A malformed value
|
|
351
|
+
* throws here instead of letting `undefined` become the current language.
|
|
351
352
|
*/
|
|
352
|
-
private readonly
|
|
353
|
-
private
|
|
354
|
-
private readonly
|
|
355
|
-
/**
|
|
356
|
-
|
|
357
|
-
* generation before its request and discards the response when it moved:
|
|
358
|
-
* a stale dictionary can never reach the cache or the signals.
|
|
359
|
-
*/
|
|
360
|
-
private readonly _generations;
|
|
361
|
-
private readonly _inflight;
|
|
362
|
-
/** Non-background loads in flight; `loadingState` follows this count. */
|
|
363
|
-
private _loadingCount;
|
|
353
|
+
private readonly _defaultLanguageId;
|
|
354
|
+
private readonly _languageStorage;
|
|
355
|
+
private readonly _currentLanguageId;
|
|
356
|
+
/** Languages already reported by the default load-error warning. */
|
|
357
|
+
private readonly _warnedLoadErrors;
|
|
364
358
|
/**
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
359
|
+
* Routes every dictionary load failure to the consumer handler, or — when
|
|
360
|
+
* none is configured — to the dev-mode warning. Warnings are deduped per
|
|
361
|
+
* language because a retry loop would otherwise flood the console; the
|
|
362
|
+
* consumer handler keeps firing per failure for telemetry.
|
|
369
363
|
*/
|
|
370
|
-
private
|
|
364
|
+
private readonly _onDictionaryLoadError;
|
|
365
|
+
private readonly _store;
|
|
371
366
|
private _initialized;
|
|
372
367
|
private readonly _tasks;
|
|
373
|
-
/**
|
|
374
|
-
* @deprecated Use `currentLanguage`, which is the same signal.
|
|
375
|
-
* Scheduled for removal before 1.0.
|
|
376
|
-
*/
|
|
377
|
-
readonly languageChanged: Signal<L>;
|
|
378
368
|
readonly languages: Signal<readonly Language<L>[]>;
|
|
379
369
|
readonly currentLanguage: Signal<L>;
|
|
380
370
|
readonly currentLanguageObject: Signal<Language<L>>;
|
|
381
371
|
readonly dir: Signal<Direction>;
|
|
382
372
|
readonly isRtl: Signal<boolean>;
|
|
383
|
-
private readonly _loadingState;
|
|
384
|
-
private readonly _loadingError;
|
|
385
373
|
/** Loader state for skeletons/spinners. */
|
|
386
374
|
readonly loadingState: Signal<"idle" | "loading" | "error">;
|
|
387
375
|
readonly loadingError: Signal<unknown>;
|
|
@@ -397,17 +385,7 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
397
385
|
* Missing-key reporting. `warnOnMissingKey` defaults to dev-mode warnings
|
|
398
386
|
* unless the consumer supplied a handler (then the handler owns reporting).
|
|
399
387
|
*/
|
|
400
|
-
private readonly
|
|
401
|
-
private readonly _missingKeys;
|
|
402
|
-
private readonly _reportedMissingKeys;
|
|
403
|
-
private readonly _pendingMissingKeys;
|
|
404
|
-
private readonly _pendingMissingEvents;
|
|
405
|
-
private _missingFlushQueued;
|
|
406
|
-
private readonly _warnOnMissingParam;
|
|
407
|
-
/** Dedupe key: `key` + NUL + `param`, so neither part can collide. */
|
|
408
|
-
private readonly _reportedMissingParams;
|
|
409
|
-
private readonly _pendingMissingParams;
|
|
410
|
-
private _missingParamsFlushQueued;
|
|
388
|
+
private readonly _missingKeyReporter;
|
|
411
389
|
/**
|
|
412
390
|
* Keys that could not be resolved from the current dictionary, the fallback
|
|
413
391
|
* dictionary, or a `defaultValue`, in the order they were first looked up.
|
|
@@ -444,11 +422,9 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
444
422
|
t(key: RegisteredI18nKey, params: TranslateParams | (() => TranslateParams)): Signal<string>;
|
|
445
423
|
t(key: RegisteredI18nKey, defaultValue: string, params?: TranslateParams | (() => TranslateParams)): Signal<string>;
|
|
446
424
|
private _resolveKeyText;
|
|
447
|
-
loadedTranslations: Signal<Record<string, unknown>>;
|
|
425
|
+
readonly loadedTranslations: Signal<Record<string, unknown>>;
|
|
448
426
|
/** Preload without switching (use in `APP_INITIALIZER` / route guards). */
|
|
449
|
-
loadTranslations(languageId: L,
|
|
450
|
-
silent?: boolean;
|
|
451
|
-
}): Promise<Record<string, unknown>>;
|
|
427
|
+
loadTranslations(languageId: L): Promise<Record<string, unknown>>;
|
|
452
428
|
/**
|
|
453
429
|
* Invalidates cached dictionaries and reloads them from the loader.
|
|
454
430
|
*
|
|
@@ -466,9 +442,6 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
466
442
|
* `onLoadError` exactly like `loadTranslations`.
|
|
467
443
|
*/
|
|
468
444
|
reload(languageId?: L): Promise<boolean>;
|
|
469
|
-
private _reloadOne;
|
|
470
|
-
private _generationOf;
|
|
471
|
-
private _invalidate;
|
|
472
445
|
/**
|
|
473
446
|
* Flips between the first two configured languages. Documentation and
|
|
474
447
|
* templates commonly place it next to `next()`/`previous()`, so it warns in
|
|
@@ -488,11 +461,8 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
488
461
|
formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
|
|
489
462
|
/** BCP-47 locale driving Intl + ICU plural rules (falls back to the id). */
|
|
490
463
|
readonly locale: Signal<string>;
|
|
491
|
-
private readonly
|
|
492
|
-
private numberFormatter;
|
|
493
|
-
private dateTimeFormatter;
|
|
464
|
+
private readonly _messageFormatter;
|
|
494
465
|
private applyLanguage;
|
|
495
|
-
private _persistLanguage;
|
|
496
466
|
private render;
|
|
497
467
|
/**
|
|
498
468
|
* Current dictionary first, then the fallback dictionary. The returned
|
|
@@ -501,81 +471,90 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
501
471
|
*/
|
|
502
472
|
private _lookupKey;
|
|
503
473
|
private _localeOf;
|
|
504
|
-
/** Loads the fallback in the background when it is not cached yet. */
|
|
505
|
-
private _ensureFallback;
|
|
506
474
|
private _hasDictionary;
|
|
507
475
|
/**
|
|
508
476
|
* Records a key no dictionary could resolve. Once per key per session; the
|
|
509
|
-
*
|
|
510
|
-
* `computed` (Angular forbids signal writes inside a computation).
|
|
477
|
+
* reporter defers the signal write so `t()` can stay a pure `computed`.
|
|
511
478
|
*/
|
|
512
479
|
private _reportMissingKey;
|
|
513
|
-
private _queueMissingFlush;
|
|
514
480
|
/**
|
|
515
481
|
* Mirrors `_reportMissingKey` for absent message arguments. The output keeps
|
|
516
482
|
* the placeholder; this only records/warns, once per (key, param) pair. The
|
|
517
483
|
* hook is deferred to a microtask for the same NG0600 reason.
|
|
518
484
|
*/
|
|
519
485
|
private _reportMissingParam;
|
|
520
|
-
private _queueMissingParamsFlush;
|
|
521
|
-
private _loadTranslations;
|
|
522
|
-
/**
|
|
523
|
-
* A dictionary reaches the visible signals only when its language is
|
|
524
|
-
* current at resolution time; a fallback dictionary fills the fallback slot.
|
|
525
|
-
* Everything else stays cached for the next switch.
|
|
526
|
-
*/
|
|
527
|
-
private _applyDictionary;
|
|
528
|
-
/** Fetch + cache + transfer. Shared by every caller; never applies. */
|
|
529
|
-
private _fetchDictionary;
|
|
530
|
-
/**
|
|
531
|
-
* Reads the persisted language. Cookie strategy: server reads the request
|
|
532
|
-
* `Cookie` header (no hydration mismatch), browser reads `document.cookie`.
|
|
533
|
-
* Everything else delegates to the SSR-safe storage helpers.
|
|
534
|
-
*/
|
|
535
|
-
private _readStored;
|
|
536
|
-
/** Persists the language. Server never writes (response cookies are app-owned). */
|
|
537
|
-
private _writeStored;
|
|
538
|
-
private transferKey;
|
|
539
|
-
/** Consumes server-rendered dictionaries so the client never refetches. */
|
|
540
|
-
private readTransfer;
|
|
541
|
-
/** Stores freshly loaded dictionaries for hydration (server only). */
|
|
542
|
-
private writeTransfer;
|
|
543
486
|
/**
|
|
544
487
|
* Exact key first, then the nested walk. Exports from some tools keep the
|
|
545
488
|
* dot in the key (`{ "app.title": "x" }`); on a collision the flat key wins.
|
|
546
489
|
*/
|
|
547
490
|
private _resolveKey;
|
|
548
|
-
private _resolveInitialLanguage;
|
|
549
491
|
static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaI18n<any>, never>;
|
|
550
492
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
551
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Type-level scan for a repeated language id. It only sees a tuple, i.e. a
|
|
496
|
+
* `languages` list written inline in the config. A hoisted `const LANGS = […]`
|
|
497
|
+
* widens to an array, where this resolves to `never` — there the runtime check
|
|
498
|
+
* thrown from `RiviniaI18n`'s constructor is the guarantee.
|
|
499
|
+
*/
|
|
500
|
+
type DuplicateLanguageId<T extends readonly {
|
|
501
|
+
readonly id: string;
|
|
502
|
+
}[], Seen extends string = never> = T extends readonly [infer Head extends {
|
|
503
|
+
readonly id: string;
|
|
504
|
+
}, ...infer Rest extends readonly {
|
|
505
|
+
readonly id: string;
|
|
506
|
+
}[]] ? Head['id'] extends Seen ? Head['id'] | DuplicateLanguageId<Rest, Seen | Head['id']> : DuplicateLanguageId<Rest, Seen | Head['id']> : never;
|
|
507
|
+
type AssertUniqueLanguageIds<T extends readonly {
|
|
508
|
+
readonly id: string;
|
|
509
|
+
}[]> = DuplicateLanguageId<T> extends (infer Duplicate) ? [Duplicate] extends [never] ? unknown : {
|
|
510
|
+
readonly duplicateLanguageId: Duplicate;
|
|
511
|
+
} : never;
|
|
552
512
|
/**
|
|
553
513
|
* Configures `@rivinia/i18n` for the application. Call once at bootstrap.
|
|
554
514
|
* Also registers an app initializer that loads the initial language before
|
|
555
515
|
* first paint (opt out with `preload: false`).
|
|
556
516
|
*
|
|
517
|
+
* A repeated id written inline (`languages: [AR, EN, AR]`) is a compile error.
|
|
518
|
+
* The check needs the array literal, so it is skipped when the call supplies
|
|
519
|
+
* the language union explicitly (`<'ar' | 'en'>`) or passes a hoisted list —
|
|
520
|
+
* both still fail at bootstrap with the runtime error. `Language` in TS terms
|
|
521
|
+
* (not this guard) is what requires `dir`.
|
|
522
|
+
*
|
|
557
523
|
* @example
|
|
558
524
|
* ```ts
|
|
559
525
|
* provideRiviniaI18n({
|
|
560
|
-
* defaultLanguage: 'ar',
|
|
561
526
|
* languages: [
|
|
562
527
|
* { id: 'ar', nativeName: 'العربية', dir: 'rtl' },
|
|
563
528
|
* { id: 'en', nativeName: 'English', dir: 'ltr' },
|
|
564
529
|
* ],
|
|
565
530
|
* })
|
|
566
531
|
* ```
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* // `as const` keeps `id` and `dir` literal — hoisted objects would
|
|
536
|
+
* // otherwise widen to `string` and fail the `Language` check.
|
|
537
|
+
* const AR = { id: 'ar', nativeName: 'العربية', dir: 'rtl' } as const;
|
|
538
|
+
* const EN = { id: 'en', nativeName: 'English', dir: 'ltr' } as const;
|
|
539
|
+
* provideRiviniaI18n<'ar' | 'en'>({
|
|
540
|
+
* languages: [AR, EN],
|
|
541
|
+
* })
|
|
542
|
+
* ```
|
|
567
543
|
*/
|
|
568
|
-
export declare function provideRiviniaI18n<L extends string>(config: RiviniaI18nConfig<L>): EnvironmentProviders;
|
|
544
|
+
export declare function provideRiviniaI18n<L extends string, const C extends RiviniaI18nConfig<L> = RiviniaI18nConfig<L>>(config: C & AssertUniqueLanguageIds<C['languages']> & RiviniaI18nConfig<L>): EnvironmentProviders;
|
|
569
545
|
/** Shorthand for `inject(RiviniaI18n)` — preserves the configured language union. */
|
|
570
546
|
export declare function injectRiviniaI18n<L extends string = string>(): RiviniaI18n<L>;
|
|
571
547
|
/**
|
|
572
548
|
* Binds a config and its typed accessors together so `L` is inferred once
|
|
573
549
|
* from the configuration instead of being lost at the injection site.
|
|
574
550
|
*
|
|
551
|
+
* Like `provideRiviniaI18n`, a repeated id in an inline `languages` list is a
|
|
552
|
+
* compile error; supplying the union explicitly or hoisting the list keeps the
|
|
553
|
+
* runtime check as the guard.
|
|
554
|
+
*
|
|
575
555
|
* @example
|
|
576
556
|
* ```ts
|
|
577
557
|
* export const i18n = defineRiviniaI18n({
|
|
578
|
-
* defaultLanguage: 'ar',
|
|
579
558
|
* languages: [
|
|
580
559
|
* { id: 'ar', nativeName: 'العربية', dir: 'rtl' },
|
|
581
560
|
* { id: 'en', nativeName: 'English', dir: 'ltr' },
|
|
@@ -587,10 +566,10 @@ export declare function injectRiviniaI18n<L extends string = string>(): RiviniaI
|
|
|
587
566
|
* const lang = i18n.inject();
|
|
588
567
|
* ```
|
|
589
568
|
*/
|
|
590
|
-
export declare function defineRiviniaI18n<L extends string>(config: RiviniaI18nConfig<L>): {
|
|
591
|
-
readonly config:
|
|
569
|
+
export declare function defineRiviniaI18n<L extends string, const C extends RiviniaI18nConfig<L> = RiviniaI18nConfig<L>>(config: C & AssertUniqueLanguageIds<C['languages']> & RiviniaI18nConfig<L>): {
|
|
570
|
+
readonly config: C;
|
|
592
571
|
provide: () => EnvironmentProviders;
|
|
593
|
-
inject: () => RiviniaI18n<
|
|
572
|
+
inject: () => RiviniaI18n<C['languages'][number]['id']>;
|
|
594
573
|
};
|
|
595
574
|
/**
|
|
596
575
|
* Progressive-enhancement wrapper around the View Transition API.
|
|
@@ -611,12 +590,12 @@ export declare class ViewTransitionService {
|
|
|
611
590
|
* lists prefer `translate()` in component code — or `t()`, which returns a
|
|
612
591
|
* signal a template can read without re-running the pipe.
|
|
613
592
|
*/
|
|
614
|
-
export declare class
|
|
593
|
+
export declare class RvTranslatePipe<L extends string = string> {
|
|
615
594
|
private readonly _i18n;
|
|
616
595
|
transform(key: RegisteredI18nKey, defaultValue?: string, params?: TranslateParams): string;
|
|
617
596
|
transform(key: RegisteredI18nKey, params?: TranslateParams): string;
|
|
618
597
|
transform(translations: Translation<L>): string;
|
|
619
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<
|
|
620
|
-
static ɵpipe: i0.ɵɵPipeDeclaration<
|
|
598
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RvTranslatePipe<any>, never>;
|
|
599
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<RvTranslatePipe<any>, "rvTranslate", true>;
|
|
621
600
|
}
|
|
622
601
|
export type { Direction, HttpLoaderOptions, IcuFormatOptions, Language, LoaderContext, LoaderDescriptor, MissingKeyEvent, MissingParamEvent, RegisteredI18nKey, RemoteLoaderOptions, RiviniaI18nConfig, RiviniaI18nKeyRegistry, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|