@rivinia/i18n 0.3.3 → 0.4.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 +374 -153
- package/cli/rivinia-i18n-keys.mjs +165 -0
- package/fesm2022/{rivinia-i18n-http-loader.impl-DVlKmSDL.mjs → rivinia-i18n-http-loader.impl--BRii7w1.mjs} +5 -3
- package/fesm2022/rivinia-i18n-http-loader.impl--BRii7w1.mjs.map +1 -0
- package/fesm2022/{rivinia-i18n-json-loader.impl-VXwAmyWL.mjs → rivinia-i18n-json-loader.impl-Bq-W-UW9.mjs} +5 -3
- package/fesm2022/rivinia-i18n-json-loader.impl-Bq-W-UW9.mjs.map +1 -0
- package/fesm2022/rivinia-i18n-loader-url-B9SlR1XB.mjs +11 -0
- package/fesm2022/rivinia-i18n-loader-url-B9SlR1XB.mjs.map +1 -0
- package/fesm2022/{rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs → rivinia-i18n-remote-loader.impl-CqKS6JWN.mjs} +4 -3
- package/fesm2022/rivinia-i18n-remote-loader.impl-CqKS6JWN.mjs.map +1 -0
- package/fesm2022/rivinia-i18n.mjs +397 -62
- package/fesm2022/rivinia-i18n.mjs.map +1 -1
- package/package.json +5 -2
- package/types/rivinia-i18n.d.ts +204 -50
- package/fesm2022/rivinia-i18n-http-loader.impl-DVlKmSDL.mjs.map +0 -1
- package/fesm2022/rivinia-i18n-json-loader.impl-VXwAmyWL.mjs.map +0 -1
- package/fesm2022/rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs.map +0 -1
package/types/rivinia-i18n.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { EnvironmentProviders,
|
|
2
|
+
import { EnvironmentProviders, Signal } from "@angular/core";
|
|
3
3
|
/** Text rendering direction. */
|
|
4
4
|
type Direction = 'ltr' | 'rtl';
|
|
5
5
|
/**
|
|
@@ -22,8 +22,12 @@ interface Language<T extends string = string> {
|
|
|
22
22
|
type Translation<T extends string> = Record<T, string>;
|
|
23
23
|
/** Persistence backend. SSR-safe: everything degrades to no-op off-browser. */
|
|
24
24
|
type StorageStrategy = 'local' | 'session' | 'none' | 'cookie';
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Interpolation + ICU params (`{count}`, `{gender}`, `{day, date}`).
|
|
27
|
+
* `Date` values are consumed by `{d, date[, style]}`; a plain `{name}`
|
|
28
|
+
* renders them with `String(value)`.
|
|
29
|
+
*/
|
|
30
|
+
type TranslateParams = Record<string, string | number | boolean | Date>;
|
|
27
31
|
interface ViewTransitionInfo {
|
|
28
32
|
readonly language: string;
|
|
29
33
|
readonly direction: Direction;
|
|
@@ -35,20 +39,36 @@ interface ViewTransitionConfig {
|
|
|
35
39
|
}
|
|
36
40
|
/** `'instant'`: flip now, load in background. `'preload-first'`: no raw-key flash. */
|
|
37
41
|
type SwitchStrategy = 'instant' | 'preload-first';
|
|
42
|
+
/**
|
|
43
|
+
* Platform facts a loader needs to build a fetchable URL.
|
|
44
|
+
*
|
|
45
|
+
* `baseUrl` mirrors `document.baseURI`: on the browser it is the document's
|
|
46
|
+
* own base, on the server it is the document's `<base href>` resolved against
|
|
47
|
+
* the incoming request. It always describes a DIRECTORY-like base the way the
|
|
48
|
+
* browser sees it (a `<base href="/app/">` keeps its trailing slash; a
|
|
49
|
+
* `<base href="/app">` does not, exactly as in the browser).
|
|
50
|
+
*/
|
|
51
|
+
interface LoaderContext {
|
|
52
|
+
/** Absolute base URL for relative dictionary paths. */
|
|
53
|
+
readonly baseUrl: string;
|
|
54
|
+
/** `true` when the application renders on the server (SSR / prerender). */
|
|
55
|
+
readonly isServer: boolean;
|
|
56
|
+
}
|
|
38
57
|
/**
|
|
39
58
|
* Pluggable key-dictionary loader. Returns a flat/nested JSON-compatible map
|
|
40
59
|
* merged into `loadedTranslations` and read by key-based `translate(key)`.
|
|
41
60
|
*/
|
|
42
61
|
interface TranslationLoader<L extends string = string> {
|
|
43
|
-
load(language: L): Promise<Record<string, unknown>>;
|
|
62
|
+
load(language: L, context?: LoaderContext): Promise<Record<string, unknown>>;
|
|
44
63
|
}
|
|
45
64
|
/**
|
|
46
65
|
* Lazy descriptor: `resolve()` dynamic-imports the real implementation, so
|
|
47
66
|
* loader code splits out of the main bundle until first use. Resolved once
|
|
48
|
-
* and cached by the service.
|
|
67
|
+
* and cached by the service. `context` lets a descriptor pick a
|
|
68
|
+
* platform-specific implementation (e.g. filesystem on the server).
|
|
49
69
|
*/
|
|
50
70
|
interface LoaderDescriptor<L extends string = string> {
|
|
51
|
-
resolve(): Promise<TranslationLoader<L>>;
|
|
71
|
+
resolve(context?: LoaderContext): Promise<TranslationLoader<L>>;
|
|
52
72
|
}
|
|
53
73
|
export declare function jsonLoader(options?: {
|
|
54
74
|
path?: string;
|
|
@@ -65,13 +85,34 @@ interface RemoteLoaderOptions {
|
|
|
65
85
|
}
|
|
66
86
|
export declare function remoteLoader(options: RemoteLoaderOptions): LoaderDescriptor<string>;
|
|
67
87
|
/** Wraps any function as a loader (mocks, in-memory, third-party SDKs). */
|
|
68
|
-
export declare function customLoader<L extends string = string>(load: (language: L) => Promise<Record<string, unknown>>): LoaderDescriptor<L>;
|
|
88
|
+
export declare function customLoader<L extends string = string>(load: (language: L, context?: LoaderContext) => Promise<Record<string, unknown>>): LoaderDescriptor<L>;
|
|
89
|
+
/**
|
|
90
|
+
* Emitted (and optionally warned about) when `translate()` cannot resolve a
|
|
91
|
+
* key from the current dictionary, the fallback dictionary, or an explicit
|
|
92
|
+
* `defaultValue`.
|
|
93
|
+
*
|
|
94
|
+
* The event is reported **once per key per session**, no matter how many
|
|
95
|
+
* times a template re-renders it. `fallbackLanguage` is present only when a
|
|
96
|
+
* fallback is configured.
|
|
97
|
+
*/
|
|
98
|
+
interface MissingKeyEvent<T extends string = string> {
|
|
99
|
+
readonly key: string;
|
|
100
|
+
readonly language: T;
|
|
101
|
+
readonly fallbackLanguage?: T;
|
|
102
|
+
}
|
|
69
103
|
/**
|
|
70
104
|
* Global configuration for `@rivinia/i18n`.
|
|
71
105
|
*/
|
|
72
106
|
interface RiviniaI18nConfig<T extends string = string> {
|
|
73
107
|
readonly languages: readonly Language<T>[];
|
|
74
108
|
readonly defaultLanguage: T;
|
|
109
|
+
/**
|
|
110
|
+
* Language used when a key is absent from the current dictionary. Must be
|
|
111
|
+
* one of `languages`. The fallback dictionary is loaded silently (it never
|
|
112
|
+
* drives `loadingState`), and its messages are rendered with the fallback
|
|
113
|
+
* language's locale — an English plural template keeps English plural rules.
|
|
114
|
+
*/
|
|
115
|
+
readonly fallbackLanguage?: T;
|
|
75
116
|
readonly storageKey?: string;
|
|
76
117
|
readonly storageStrategy?: StorageStrategy;
|
|
77
118
|
readonly autoApplyDirection?: boolean;
|
|
@@ -87,6 +128,18 @@ interface RiviniaI18nConfig<T extends string = string> {
|
|
|
87
128
|
readonly switchStrategy?: SwitchStrategy;
|
|
88
129
|
/** Called when a dictionary load fails. The service still falls back safely. */
|
|
89
130
|
readonly onLoadError?: (language: T, error: unknown) => void;
|
|
131
|
+
/**
|
|
132
|
+
* Called when `translate()` cannot resolve a key (absent from the current
|
|
133
|
+
* dictionary, from the fallback dictionary, and with no `defaultValue`).
|
|
134
|
+
* Fires once per key per session. When set, the default console warning is
|
|
135
|
+
* suppressed.
|
|
136
|
+
*/
|
|
137
|
+
readonly onMissingKey?: (event: MissingKeyEvent<T>) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Log a `console.warn` (once per key) for unresolved keys.
|
|
140
|
+
* @default isDevMode() && !onMissingKey
|
|
141
|
+
*/
|
|
142
|
+
readonly warnOnMissingKey?: boolean;
|
|
90
143
|
/**
|
|
91
144
|
* Load the initial language during provider setup (before first paint).
|
|
92
145
|
* SSR waits via `PendingTasks`. Set `false` to skip (e.g. fully inline apps
|
|
@@ -107,17 +160,28 @@ interface RiviniaI18nConfig<T extends string = string> {
|
|
|
107
160
|
readonly detectBrowser?: boolean;
|
|
108
161
|
}
|
|
109
162
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
163
|
+
* Typed-key registry. Empty by default, so `RegisteredI18nKey` resolves to
|
|
164
|
+
* `string` and nothing breaks.
|
|
165
|
+
*
|
|
166
|
+
* Augment it (usually with the generated file from `rivinia-i18n-keys`) to
|
|
167
|
+
* make every key-taking API type-checked:
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* declare module '@rivinia/i18n' {
|
|
171
|
+
* interface RiviniaI18nKeyRegistry {
|
|
172
|
+
* readonly keys: 'app.title' | 'app.save';
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* A genuinely dynamic key is asserted explicitly:
|
|
178
|
+
* ``i18n.translate(`status.${code}` as RegisteredI18nKey)``.
|
|
112
179
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
declare function safeGetItem(key: string, strategy: StorageStrategy): string | null;
|
|
119
|
-
/** SSR-safe write. Silently no-ops off-browser or on denial. */
|
|
120
|
-
declare function safeSetItem(key: string, value: string, strategy: StorageStrategy): void;
|
|
180
|
+
interface RiviniaI18nKeyRegistry {}
|
|
181
|
+
/** Every key accepted by `translate()`, `t()` and `RTranslatePipe`. */
|
|
182
|
+
type RegisteredI18nKey = RiviniaI18nKeyRegistry extends {
|
|
183
|
+
keys: infer K extends string;
|
|
184
|
+
} ? K : string;
|
|
121
185
|
/**
|
|
122
186
|
* Matches the browser language priority list against supported ids, in order.
|
|
123
187
|
* For each browser entry (highest preference first) tries the exact tag, then
|
|
@@ -139,27 +203,29 @@ export declare function serializeCookie(name: string, value: string, options?: {
|
|
|
139
203
|
secure?: boolean;
|
|
140
204
|
}): string;
|
|
141
205
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
protocol?: string;
|
|
149
|
-
hostname?: string;
|
|
150
|
-
} | null | undefined): boolean;
|
|
151
|
-
/**
|
|
152
|
-
* Minimal ICU MessageFormat subset: `{name}` interpolation, `{n, plural, …}`,
|
|
153
|
-
* `{x, select, …}`, `#` inside plurals, and nesting. Categories resolve via
|
|
154
|
-
* the native `Intl.PluralRules(locale)` — Arabic gets all six forms
|
|
155
|
-
* (zero/one/two/few/many/other) with zero extra dependencies.
|
|
206
|
+
* Minimal ICU MessageFormat (MF1) subset: `{name}` interpolation,
|
|
207
|
+
* `{n, plural, …}` (with `offset:`), `{n, selectordinal, …}`, `{x, select, …}`,
|
|
208
|
+
* `#` inside plural-style arguments, `{n, number[, style]}`, `{d, date[, style]}`,
|
|
209
|
+
* and nesting. Categories resolve via the native `Intl.PluralRules(locale)` —
|
|
210
|
+
* Arabic gets all six forms (zero/one/two/few/many/other) with zero extra
|
|
211
|
+
* dependencies.
|
|
156
212
|
*
|
|
157
213
|
* Supported (and ONLY these — documented subset, translators beware):
|
|
158
214
|
* - `{count, plural, =0 {none} one {# item} other {# items}}`
|
|
215
|
+
* - `{count, plural, offset:1 =0 {none} one {you and # other} other {you and # others}}`
|
|
216
|
+
* - `{place, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}`
|
|
159
217
|
* - `{gender, select, male {He} female {She} other {They}}`
|
|
218
|
+
* - `{amount, number}`, `{ratio, number, percent}`, `{count, number, integer}`,
|
|
219
|
+
* `{price, number, ::currency/USD}`
|
|
220
|
+
* - `{day, date}`, `{day, date, short|medium|long|full}`
|
|
160
221
|
* - `{name}` plain interpolation (missing params keep the placeholder)
|
|
161
222
|
*
|
|
162
|
-
*
|
|
223
|
+
* Offset semantics follow ICU (ICU4J `PluralFormat`): an explicit `=N` matches
|
|
224
|
+
* the RAW argument value, the plural category is selected with
|
|
225
|
+
* `value - offset`, and `#` renders `value - offset` in the locale's digits.
|
|
226
|
+
*
|
|
227
|
+
* Unsupported or malformed constructs never throw: the raw `{…}` segment is
|
|
228
|
+
* returned as-is and parsing continues after it.
|
|
163
229
|
*/
|
|
164
230
|
export declare function formatIcu(template: string, params: TranslateParams, locale: string): string;
|
|
165
231
|
/**
|
|
@@ -174,6 +240,8 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
174
240
|
private readonly _storageKey;
|
|
175
241
|
private readonly _storageStrategy;
|
|
176
242
|
private readonly _autoApplyDirection;
|
|
243
|
+
/** Validated once; `null` means no fallback chain. */
|
|
244
|
+
private readonly _fallbackId;
|
|
177
245
|
/**
|
|
178
246
|
* Injected (not global) document: the dir/lang effect renders on the
|
|
179
247
|
* server too, avoiding an RTL first-paint shift on hydration.
|
|
@@ -183,9 +251,21 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
183
251
|
/** Present only on the server: used for cookie reads + transfer writes. */
|
|
184
252
|
private readonly _request;
|
|
185
253
|
private readonly _transfer;
|
|
254
|
+
/**
|
|
255
|
+
* Platform facts for loaders, built once: `REQUEST` + `<base href>` on the
|
|
256
|
+
* server, `document.baseURI` in the browser. This is what makes the default
|
|
257
|
+
* loader work under SSR instead of fetching a relative URL Node cannot parse.
|
|
258
|
+
*/
|
|
259
|
+
readonly loaderContext: LoaderContext;
|
|
186
260
|
private readonly _currentLanguageId;
|
|
187
261
|
private readonly _languages;
|
|
188
262
|
private readonly _loadedTranslations;
|
|
263
|
+
/**
|
|
264
|
+
* The fallback dictionary, kept separate from `_loadedTranslations` (which
|
|
265
|
+
* always mirrors the VISIBLE language). A signal so `t()`'s computed
|
|
266
|
+
* re-evaluates when the fallback arrives.
|
|
267
|
+
*/
|
|
268
|
+
private readonly _fallbackDict;
|
|
189
269
|
/**
|
|
190
270
|
* Explicit loader wins; otherwise the conventional JSON layout
|
|
191
271
|
* (`i18n/{language}.json` — files in `public/i18n/`, served from the site
|
|
@@ -196,6 +276,12 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
196
276
|
private readonly _getLoader;
|
|
197
277
|
private _resolvedLoader;
|
|
198
278
|
private readonly _translationsCache;
|
|
279
|
+
/**
|
|
280
|
+
* Per-language generation, bumped by `reload()`. A load captures the
|
|
281
|
+
* generation before its request and discards the response when it moved:
|
|
282
|
+
* a stale dictionary can never reach the cache or the signals.
|
|
283
|
+
*/
|
|
284
|
+
private readonly _generations;
|
|
199
285
|
private readonly _inflight;
|
|
200
286
|
/**
|
|
201
287
|
* Out-of-order safety: a response reaches the visible signals only when it
|
|
@@ -206,25 +292,43 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
206
292
|
private _applyCount;
|
|
207
293
|
private _initialized;
|
|
208
294
|
private readonly _tasks;
|
|
209
|
-
readonly languageChanged:
|
|
210
|
-
readonly languages:
|
|
211
|
-
readonly currentLanguage:
|
|
212
|
-
readonly currentLanguageObject:
|
|
213
|
-
readonly dir:
|
|
214
|
-
readonly isRtl:
|
|
295
|
+
readonly languageChanged: Signal<L>;
|
|
296
|
+
readonly languages: Signal<readonly Language<L>[]>;
|
|
297
|
+
readonly currentLanguage: Signal<L>;
|
|
298
|
+
readonly currentLanguageObject: Signal<Language<L>>;
|
|
299
|
+
readonly dir: Signal<Direction>;
|
|
300
|
+
readonly isRtl: Signal<boolean>;
|
|
215
301
|
private readonly _loadingState;
|
|
216
302
|
private readonly _loadingError;
|
|
217
303
|
/** Loader state for skeletons/spinners. */
|
|
218
|
-
readonly loadingState:
|
|
219
|
-
readonly loadingError:
|
|
220
|
-
readonly isLoading:
|
|
304
|
+
readonly loadingState: Signal<"error" | "idle" | "loading">;
|
|
305
|
+
readonly loadingError: Signal<unknown>;
|
|
306
|
+
readonly isLoading: Signal<boolean>;
|
|
221
307
|
private readonly _ready;
|
|
222
308
|
/**
|
|
223
309
|
* True once the initial language content is available (inline seed and/or
|
|
224
310
|
* initial load settled) — or immediately when `preload: false` skips setup
|
|
225
311
|
* loading. Gate first-paint skeletons on this, not on `isLoading`.
|
|
226
312
|
*/
|
|
227
|
-
readonly ready:
|
|
313
|
+
readonly ready: Signal<boolean>;
|
|
314
|
+
/**
|
|
315
|
+
* Missing-key reporting. `warnOnMissingKey` defaults to dev-mode warnings
|
|
316
|
+
* unless the consumer supplied a handler (then the handler owns reporting).
|
|
317
|
+
*/
|
|
318
|
+
private readonly _warnOnMissingKey;
|
|
319
|
+
private readonly _missingKeys;
|
|
320
|
+
private readonly _reportedMissingKeys;
|
|
321
|
+
private readonly _pendingMissingKeys;
|
|
322
|
+
private _missingFlushQueued;
|
|
323
|
+
/**
|
|
324
|
+
* Keys that could not be resolved from the current dictionary, the fallback
|
|
325
|
+
* dictionary, or a `defaultValue`, in the order they were first looked up.
|
|
326
|
+
* Published in a microtask because `t()` is a `computed` and Angular forbids
|
|
327
|
+
* signal writes inside a computation.
|
|
328
|
+
*/
|
|
329
|
+
readonly missingKeys: Signal<readonly string[]>;
|
|
330
|
+
/** Resets the report (and the once-per-key dedupe), e.g. after a fix. */
|
|
331
|
+
clearMissingKeys(): void;
|
|
228
332
|
constructor();
|
|
229
333
|
getLanguage(id: L): Language<L> | undefined;
|
|
230
334
|
/**
|
|
@@ -235,14 +339,46 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
235
339
|
* `loadingError`/`onLoadError`, inline seeds are preserved).
|
|
236
340
|
*/
|
|
237
341
|
initialize(): Promise<void>;
|
|
238
|
-
translate(key:
|
|
239
|
-
translate(key:
|
|
342
|
+
translate(key: RegisteredI18nKey, defaultValue?: string, params?: TranslateParams): string;
|
|
343
|
+
translate(key: RegisteredI18nKey, params?: TranslateParams): string;
|
|
240
344
|
translate(translations: Translation<L>): string;
|
|
241
|
-
|
|
345
|
+
/**
|
|
346
|
+
* A `computed` over the same resolution chain as `translate()` — for
|
|
347
|
+
* component fields (`readonly title = i18n.t('home.title')`), not for
|
|
348
|
+
* calling from a template expression on every change detection.
|
|
349
|
+
*
|
|
350
|
+
* A function `params` is invoked inside the computation, so the signals it
|
|
351
|
+
* reads are tracked and a change re-renders the text.
|
|
352
|
+
*/
|
|
353
|
+
t(key: RegisteredI18nKey): Signal<string>;
|
|
354
|
+
t(key: RegisteredI18nKey, params: TranslateParams | (() => TranslateParams)): Signal<string>;
|
|
355
|
+
t(key: RegisteredI18nKey, defaultValue: string, params?: TranslateParams | (() => TranslateParams)): Signal<string>;
|
|
356
|
+
private _resolveKeyText;
|
|
357
|
+
loadedTranslations: Signal<Record<string, unknown>>;
|
|
242
358
|
/** Preload without switching (use in `APP_INITIALIZER` / route guards). */
|
|
243
359
|
loadTranslations(languageId: L, opts?: {
|
|
244
360
|
silent?: boolean;
|
|
245
361
|
}): Promise<Record<string, unknown>>;
|
|
362
|
+
/**
|
|
363
|
+
* Invalidates cached dictionaries and reloads them from the loader.
|
|
364
|
+
*
|
|
365
|
+
* - `reload()` — refreshes the current language (and the fallback, when
|
|
366
|
+
* configured) and drops every OTHER cached dictionary, so the next switch
|
|
367
|
+
* refetches. Resolves `true` when the current language loaded.
|
|
368
|
+
* - `reload(lang)` — refreshes one language. If it is the current one it is
|
|
369
|
+
* applied; otherwise it is only re-cached (and refreshed in the fallback
|
|
370
|
+
* slot when it is the fallback).
|
|
371
|
+
*
|
|
372
|
+
* The visible dictionary stays on screen until the fresh one arrives
|
|
373
|
+
* (stale-while-revalidate), so a reload never flashes raw keys.
|
|
374
|
+
*
|
|
375
|
+
* Never rejects: failures land on `loadingState`, `loadingError` and
|
|
376
|
+
* `onLoadError` exactly like `loadTranslations`.
|
|
377
|
+
*/
|
|
378
|
+
reload(languageId?: L): Promise<boolean>;
|
|
379
|
+
private _reloadOne;
|
|
380
|
+
private _generationOf;
|
|
381
|
+
private _invalidate;
|
|
246
382
|
toggle(): void;
|
|
247
383
|
next(): void;
|
|
248
384
|
previous(): void;
|
|
@@ -255,12 +391,29 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
255
391
|
/** Date/time formatting bound to the current language locale (cached Intl). */
|
|
256
392
|
formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
|
|
257
393
|
/** BCP-47 locale driving Intl + ICU plural rules (falls back to the id). */
|
|
258
|
-
readonly locale:
|
|
394
|
+
readonly locale: Signal<string>;
|
|
259
395
|
private readonly _formatters;
|
|
260
396
|
private numberFormatter;
|
|
261
397
|
private dateTimeFormatter;
|
|
262
398
|
private applyLanguage;
|
|
263
399
|
private render;
|
|
400
|
+
/**
|
|
401
|
+
* Current dictionary first, then the fallback dictionary. The returned
|
|
402
|
+
* locale belongs to the dictionary the text came from: an English plural
|
|
403
|
+
* template borrowed by an Arabic UI must use English plural rules.
|
|
404
|
+
*/
|
|
405
|
+
private _lookupKey;
|
|
406
|
+
private _localeOf;
|
|
407
|
+
/** Loads the fallback in the background when it is not cached yet. */
|
|
408
|
+
private _ensureFallback;
|
|
409
|
+
private _hasDictionary;
|
|
410
|
+
/**
|
|
411
|
+
* Records a key no dictionary could resolve. Once per key per session; the
|
|
412
|
+
* signal write is deferred to a microtask so `t()` can stay a pure
|
|
413
|
+
* `computed` (Angular forbids signal writes inside a computation).
|
|
414
|
+
*/
|
|
415
|
+
private _reportMissingKey;
|
|
416
|
+
private _queueMissingFlush;
|
|
264
417
|
private _loadTranslations;
|
|
265
418
|
/**
|
|
266
419
|
* Reads the persisted language. Cookie strategy: server reads the request
|
|
@@ -335,14 +488,15 @@ export declare class ViewTransitionService {
|
|
|
335
488
|
*
|
|
336
489
|
* Impure (`pure: false`) by necessity: the service reads signals on every
|
|
337
490
|
* call, and a pure pipe would not re-evaluate on language switches. For long
|
|
338
|
-
* lists prefer `translate()` in component code
|
|
491
|
+
* lists prefer `translate()` in component code — or `t()`, which returns a
|
|
492
|
+
* signal a template can read without re-running the pipe.
|
|
339
493
|
*/
|
|
340
494
|
export declare class RTranslatePipe<L extends string = string> {
|
|
341
495
|
private readonly _i18n;
|
|
342
|
-
transform(key:
|
|
343
|
-
transform(key:
|
|
496
|
+
transform(key: RegisteredI18nKey, defaultValue?: string, params?: TranslateParams): string;
|
|
497
|
+
transform(key: RegisteredI18nKey, params?: TranslateParams): string;
|
|
344
498
|
transform(translations: Translation<L>): string;
|
|
345
499
|
static ɵfac: i0.ɵɵFactoryDeclaration<RTranslatePipe<any>, never>;
|
|
346
500
|
static ɵpipe: i0.ɵɵPipeDeclaration<RTranslatePipe<any>, "rTranslate", true>;
|
|
347
501
|
}
|
|
348
|
-
export type { Direction, HttpLoaderOptions, Language, LoaderDescriptor, RemoteLoaderOptions, RiviniaI18nConfig, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|
|
502
|
+
export type { Direction, HttpLoaderOptions, Language, LoaderContext, LoaderDescriptor, MissingKeyEvent, RegisteredI18nKey, RemoteLoaderOptions, RiviniaI18nConfig, RiviniaI18nKeyRegistry, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-http-loader.impl-DVlKmSDL.mjs","names":[],"sources":["../../../projects/i18n/src/lib/http-loader.impl.ts"],"sourcesContent":["import type { HttpLoaderOptions, TranslationLoader } from './loaders';\n\nexport class HttpLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options: HttpLoaderOptions) {}\n\n async load(language: L): Promise<Record<string, unknown>> {\n const url = this._options.buildUrl?.(language) ?? `${this._options.endpoint}/${language}`;\n const response = await fetch(url, { method: this._options.method ?? 'GET' });\n if (!response.ok) {\n throw new Error(`[rivinia/i18n] Failed to load \"${url}\": ${response.statusText}`);\n }\n return response.json();\n }\n}\n"],"mappings":"AAEA,IAAa,aAAb,MAAuB;CACQ;CAA7B,YAA6B,UAA2B;EAA3B,KAAA,WAAA;CAA8B;CAE3D,MAAM,KAAK,UAAW;EACpB,MAAM,MAAM,KAAK,SAAS,WAAW,QAAQ,KAAK,GAAG,KAAK,SAAS,SAAQ,GAAI;EAC/E,MAAM,WAAW,MAAM,MAAM,KAAK,EAAE,QAAQ,KAAK,SAAS,UAAU,MAAK,CAAE;EAC3E,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,kCAAkC,IAAG,KAAM,SAAS,YAAY;EAElF,OAAO,SAAS,KAAI;CACtB;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-json-loader.impl-VXwAmyWL.mjs","names":[],"sources":["../../../projects/i18n/src/lib/json-loader.impl.ts"],"sourcesContent":["import type { TranslationLoader } from './loaders';\n\nconst DEFAULT_BASE_PATH = 'i18n';\n\nexport class JsonLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options?: { path?: string }) {}\n\n async load(language: L): Promise<Record<string, unknown>> {\n const basePath = this._options?.path ?? DEFAULT_BASE_PATH;\n const url = `${basePath}/${language}.json`;\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`[rivinia/i18n] Failed to load \"${url}\": ${response.statusText}`);\n }\n return response.json();\n }\n}\n"],"mappings":"AAEA,MAAM,oBAAoB;AAE1B,IAAa,aAAb,MAAuB;CACQ;CAA7B,YAA6B,UAA4B;EAA5B,KAAA,WAAA;CAA+B;CAE5D,MAAM,KAAK,UAAW;EAEpB,MAAM,MAAM,GADK,KAAK,UAAU,QAAQ,kBACjB,GAAI,SAAQ;EACnC,MAAM,WAAW,MAAM,MAAM,GAAG;EAChC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,kCAAkC,IAAG,KAAM,SAAS,YAAY;EAElF,OAAO,SAAS,KAAI;CACtB;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs","names":[],"sources":["../../../projects/i18n/src/lib/remote-loader.impl.ts"],"sourcesContent":["import type { RemoteLoaderOptions, TranslationLoader } from './loaders';\n\nexport class RemoteLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options: RemoteLoaderOptions) {}\n\n async load(language: L): Promise<Record<string, unknown>> {\n const url = this._options.url(language);\n const response = await fetch(url, { headers: this._options.headers });\n if (!response.ok) {\n throw new Error(`[rivinia/i18n] Failed to load \"${url}\": ${response.statusText}`);\n }\n return response.json();\n }\n}\n"],"mappings":"AAEA,IAAa,eAAb,MAAyB;CACM;CAA7B,YAA6B,UAA6B;EAA7B,KAAA,WAAA;CAAgC;CAE7D,MAAM,KAAK,UAAW;EACpB,MAAM,MAAM,KAAK,SAAS,IAAI,QAAQ;EACtC,MAAM,WAAW,MAAM,MAAM,KAAK,EAAE,SAAS,KAAK,SAAS,QAAO,CAAE;EACpE,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,kCAAkC,IAAG,KAAM,SAAS,YAAY;EAElF,OAAO,SAAS,KAAI;CACtB;AACD"}
|