@rivinia/i18n 0.4.0 → 0.6.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/CHANGELOG.md +131 -0
- package/README.md +96 -13
- package/cli/rivinia-i18n-keys.mjs +267 -32
- package/fesm2022/rivinia-i18n-http-loader.impl-sLjTazQZ.mjs +20 -0
- package/fesm2022/rivinia-i18n-http-loader.impl-sLjTazQZ.mjs.map +1 -0
- package/fesm2022/rivinia-i18n-remote-loader.impl-DE90KQn_.mjs +19 -0
- package/fesm2022/rivinia-i18n-remote-loader.impl-DE90KQn_.mjs.map +1 -0
- package/fesm2022/rivinia-i18n.mjs +822 -432
- package/fesm2022/rivinia-i18n.mjs.map +1 -1
- package/package.json +22 -1
- package/types/rivinia-i18n.d.ts +128 -84
- package/fesm2022/rivinia-i18n-http-loader.impl--BRii7w1.mjs +0 -17
- package/fesm2022/rivinia-i18n-http-loader.impl--BRii7w1.mjs.map +0 -1
- package/fesm2022/rivinia-i18n-json-loader.impl-Bq-W-UW9.mjs +0 -18
- package/fesm2022/rivinia-i18n-json-loader.impl-Bq-W-UW9.mjs.map +0 -1
- package/fesm2022/rivinia-i18n-loader-url-B9SlR1XB.mjs +0 -11
- package/fesm2022/rivinia-i18n-loader-url-B9SlR1XB.mjs.map +0 -1
- package/fesm2022/rivinia-i18n-remote-loader.impl-CqKS6JWN.mjs +0 -16
- package/fesm2022/rivinia-i18n-remote-loader.impl-CqKS6JWN.mjs.map +0 -1
package/types/rivinia-i18n.d.ts
CHANGED
|
@@ -28,10 +28,12 @@ type StorageStrategy = 'local' | 'session' | 'none' | 'cookie';
|
|
|
28
28
|
* renders them with `String(value)`.
|
|
29
29
|
*/
|
|
30
30
|
type TranslateParams = Record<string, string | number | boolean | Date>;
|
|
31
|
+
/** @experimental The view-transition integration may change before 1.0. */
|
|
31
32
|
interface ViewTransitionInfo {
|
|
32
33
|
readonly language: string;
|
|
33
34
|
readonly direction: Direction;
|
|
34
35
|
}
|
|
36
|
+
/** @experimental The view-transition integration may change before 1.0. */
|
|
35
37
|
interface ViewTransitionConfig {
|
|
36
38
|
readonly enabled?: boolean;
|
|
37
39
|
readonly skipInitialTransition?: boolean;
|
|
@@ -70,6 +72,12 @@ interface TranslationLoader<L extends string = string> {
|
|
|
70
72
|
interface LoaderDescriptor<L extends string = string> {
|
|
71
73
|
resolve(context?: LoaderContext): Promise<TranslationLoader<L>>;
|
|
72
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The conventional `i18n/{language}.json` loader, and the service's default.
|
|
77
|
+
* Deliberately NOT code-split: it runs in the app initializer, so a lazy chunk
|
|
78
|
+
* would add two script round-trips (loader + its URL helper) before the first
|
|
79
|
+
* dictionary fetch. `httpLoader`/`remoteLoader` stay lazy — they are opt-in.
|
|
80
|
+
*/
|
|
73
81
|
export declare function jsonLoader(options?: {
|
|
74
82
|
path?: string;
|
|
75
83
|
}): LoaderDescriptor<string>;
|
|
@@ -100,6 +108,16 @@ interface MissingKeyEvent<T extends string = string> {
|
|
|
100
108
|
readonly language: T;
|
|
101
109
|
readonly fallbackLanguage?: T;
|
|
102
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Emitted (and optionally warned about) when a resolved message needs a named
|
|
113
|
+
* argument that the caller did not pass. Reported **once per (key, param)
|
|
114
|
+
* pair per session**; the placeholder stays in the output.
|
|
115
|
+
*/
|
|
116
|
+
interface MissingParamEvent<T extends string = string> {
|
|
117
|
+
readonly key: string;
|
|
118
|
+
readonly param: string;
|
|
119
|
+
readonly language: T;
|
|
120
|
+
}
|
|
103
121
|
/**
|
|
104
122
|
* Global configuration for `@rivinia/i18n`.
|
|
105
123
|
*/
|
|
@@ -140,6 +158,25 @@ interface RiviniaI18nConfig<T extends string = string> {
|
|
|
140
158
|
* @default isDevMode() && !onMissingKey
|
|
141
159
|
*/
|
|
142
160
|
readonly warnOnMissingKey?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Called once per (key, param) pair when a message needs a named argument
|
|
163
|
+
* that `params` does not provide. The placeholder is still rendered
|
|
164
|
+
* unchanged. Delivered from a microtask, like `onMissingKey`.
|
|
165
|
+
*/
|
|
166
|
+
readonly onMissingParam?: (event: MissingParamEvent<T>) => void;
|
|
167
|
+
/**
|
|
168
|
+
* Log a `console.warn` (once per key/param pair) for missing arguments.
|
|
169
|
+
* @default isDevMode() && !onMissingParam
|
|
170
|
+
*/
|
|
171
|
+
readonly warnOnMissingParam?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Persist the language to storage/cookie after a user-initiated switch
|
|
174
|
+
* (`setLanguage`, `toggle`, `next`, `previous`, `setLanguageAsync`). The
|
|
175
|
+
* initial language is never written, so a cookie is only set once the user
|
|
176
|
+
* actually chooses a language.
|
|
177
|
+
* @default true
|
|
178
|
+
*/
|
|
179
|
+
readonly persist?: boolean;
|
|
143
180
|
/**
|
|
144
181
|
* Load the initial language during provider setup (before first paint).
|
|
145
182
|
* SSR waits via `PendingTasks`. Set `false` to skip (e.g. fully inline apps
|
|
@@ -159,6 +196,21 @@ interface RiviniaI18nConfig<T extends string = string> {
|
|
|
159
196
|
*/
|
|
160
197
|
readonly detectBrowser?: boolean;
|
|
161
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* A dictionary request that reached the network and failed.
|
|
201
|
+
*
|
|
202
|
+
* `statusText` is empty on HTTP/2 (measured: Chrome reports an empty string
|
|
203
|
+
* for a 404 over h2), so the message carries the numeric status instead.
|
|
204
|
+
* Passed to `RiviniaI18nConfig.onLoadError`.
|
|
205
|
+
*/
|
|
206
|
+
export declare class RiviniaLoadError extends Error {
|
|
207
|
+
readonly url: string;
|
|
208
|
+
readonly status: number;
|
|
209
|
+
readonly language: string;
|
|
210
|
+
constructor(url: string, status: number, language: string, options?: {
|
|
211
|
+
cause?: unknown;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
162
214
|
/**
|
|
163
215
|
* Typed-key registry. Empty by default, so `RegisteredI18nKey` resolves to
|
|
164
216
|
* `string` and nothing breaks.
|
|
@@ -178,7 +230,7 @@ interface RiviniaI18nConfig<T extends string = string> {
|
|
|
178
230
|
* ``i18n.translate(`status.${code}` as RegisteredI18nKey)``.
|
|
179
231
|
*/
|
|
180
232
|
interface RiviniaI18nKeyRegistry {}
|
|
181
|
-
/** Every key accepted by `translate()`, `t()` and `
|
|
233
|
+
/** Every key accepted by `translate()`, `t()` and the `rvTranslate` pipe. */
|
|
182
234
|
type RegisteredI18nKey = RiviniaI18nKeyRegistry extends {
|
|
183
235
|
keys: infer K extends string;
|
|
184
236
|
} ? K : string;
|
|
@@ -187,28 +239,46 @@ type RegisteredI18nKey = RiviniaI18nKeyRegistry extends {
|
|
|
187
239
|
* For each browser entry (highest preference first) tries the exact tag, then
|
|
188
240
|
* its base subtag (`ar-EG` → `ar`). Returns the first hit, or `null`.
|
|
189
241
|
* Pure and exported for testing — pass `navigator.languages` in app code.
|
|
242
|
+
* @internal May move to an `@rivinia/i18n/internal` entry point before 1.0.
|
|
190
243
|
*/
|
|
191
244
|
export declare function detectBrowserLanguage<T extends string>(supportedIds: readonly T[], browserLanguages: readonly string[] | undefined): T | null;
|
|
192
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* Browser language list, `undefined` off-browser (SSR-safe input for detection).
|
|
247
|
+
* @internal May move to an `@rivinia/i18n/internal` entry point before 1.0.
|
|
248
|
+
*/
|
|
193
249
|
export declare function browserLanguages(): readonly string[] | undefined;
|
|
194
250
|
/**
|
|
195
251
|
* Cookie helpers for the `'cookie'` storage strategy. Pure and SSR-testable:
|
|
196
252
|
* the service supplies the header (server `REQUEST`) or `document.cookie`
|
|
197
253
|
* (browser); these functions only parse and serialize.
|
|
198
254
|
*/
|
|
199
|
-
/**
|
|
255
|
+
/**
|
|
256
|
+
* Extracts a cookie value by name from a `Cookie` header or `document.cookie`.
|
|
257
|
+
* @internal Exported for the package's own SSR tests; may move to an
|
|
258
|
+
* `@rivinia/i18n/internal` entry point before 1.0.
|
|
259
|
+
*/
|
|
200
260
|
export declare function parseCookie(header: string | null | undefined, name: string): string | null;
|
|
201
|
-
/**
|
|
261
|
+
/**
|
|
262
|
+
* Serializes a language cookie (Lax, root path, one year).
|
|
263
|
+
* @internal Exported for the package's own SSR tests; may move to an
|
|
264
|
+
* `@rivinia/i18n/internal` entry point before 1.0.
|
|
265
|
+
*/
|
|
202
266
|
export declare function serializeCookie(name: string, value: string, options?: {
|
|
203
267
|
secure?: boolean;
|
|
204
268
|
}): string;
|
|
269
|
+
/**
|
|
270
|
+
* Tolerant hooks for one render. `onMissingParam` fires for each named
|
|
271
|
+
* argument that the message needs but `params` does not provide; the
|
|
272
|
+
* placeholder is still rendered unchanged.
|
|
273
|
+
*/
|
|
274
|
+
interface IcuFormatOptions {
|
|
275
|
+
readonly onMissingParam?: (name: string) => void;
|
|
276
|
+
}
|
|
205
277
|
/**
|
|
206
278
|
* Minimal ICU MessageFormat (MF1) subset: `{name}` interpolation,
|
|
207
279
|
* `{n, plural, …}` (with `offset:`), `{n, selectordinal, …}`, `{x, select, …}`,
|
|
208
280
|
* `#` inside plural-style arguments, `{n, number[, style]}`, `{d, date[, style]}`,
|
|
209
|
-
*
|
|
210
|
-
* Arabic gets all six forms (zero/one/two/few/many/other) with zero extra
|
|
211
|
-
* dependencies.
|
|
281
|
+
* nesting, and ICU apostrophe quoting.
|
|
212
282
|
*
|
|
213
283
|
* Supported (and ONLY these — documented subset, translators beware):
|
|
214
284
|
* - `{count, plural, =0 {none} one {# item} other {# items}}`
|
|
@@ -219,15 +289,19 @@ export declare function serializeCookie(name: string, value: string, options?: {
|
|
|
219
289
|
* `{price, number, ::currency/USD}`
|
|
220
290
|
* - `{day, date}`, `{day, date, short|medium|long|full}`
|
|
221
291
|
* - `{name}` plain interpolation (missing params keep the placeholder)
|
|
292
|
+
* - `''` → one apostrophe; `'{'…'}'` quotes a literal brace
|
|
222
293
|
*
|
|
223
294
|
* Offset semantics follow ICU (ICU4J `PluralFormat`): an explicit `=N` matches
|
|
224
295
|
* the RAW argument value, the plural category is selected with
|
|
225
296
|
* `value - offset`, and `#` renders `value - offset` in the locale's digits.
|
|
226
297
|
*
|
|
298
|
+
* Templates are compiled once into an AST and cached (bounded LRU), so a
|
|
299
|
+
* template rendered on every change-detection pass is not re-parsed.
|
|
300
|
+
*
|
|
227
301
|
* Unsupported or malformed constructs never throw: the raw `{…}` segment is
|
|
228
302
|
* returned as-is and parsing continues after it.
|
|
229
303
|
*/
|
|
230
|
-
export declare function formatIcu(template: string, params: TranslateParams, locale: string): string;
|
|
304
|
+
export declare function formatIcu(template: string, params: TranslateParams, locale: string, options?: IcuFormatOptions): string;
|
|
231
305
|
/**
|
|
232
306
|
* Headless language owner. State (signals, readonly): current language,
|
|
233
307
|
* direction, loader status, dictionaries. Changes only via the methods below.
|
|
@@ -237,8 +311,6 @@ export declare function formatIcu(template: string, params: TranslateParams, loc
|
|
|
237
311
|
export declare class RiviniaI18n<L extends string = string> {
|
|
238
312
|
private readonly _config;
|
|
239
313
|
private readonly _viewTransition;
|
|
240
|
-
private readonly _storageKey;
|
|
241
|
-
private readonly _storageStrategy;
|
|
242
314
|
private readonly _autoApplyDirection;
|
|
243
315
|
/** Validated once; `null` means no fallback chain. */
|
|
244
316
|
private readonly _fallbackId;
|
|
@@ -251,57 +323,27 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
251
323
|
/** Present only on the server: used for cookie reads + transfer writes. */
|
|
252
324
|
private readonly _request;
|
|
253
325
|
private readonly _transfer;
|
|
326
|
+
private readonly _direction;
|
|
254
327
|
/**
|
|
255
328
|
* Platform facts for loaders, built once: `REQUEST` + `<base href>` on the
|
|
256
329
|
* server, `document.baseURI` in the browser. This is what makes the default
|
|
257
330
|
* loader work under SSR instead of fetching a relative URL Node cannot parse.
|
|
258
331
|
*/
|
|
259
332
|
readonly loaderContext: LoaderContext;
|
|
260
|
-
|
|
333
|
+
/** Declared before the storage collaborator: it reads this during setup. */
|
|
261
334
|
private readonly _languages;
|
|
262
|
-
private readonly
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
* always mirrors the VISIBLE language). A signal so `t()`'s computed
|
|
266
|
-
* re-evaluates when the fallback arrives.
|
|
267
|
-
*/
|
|
268
|
-
private readonly _fallbackDict;
|
|
269
|
-
/**
|
|
270
|
-
* Explicit loader wins; otherwise the conventional JSON layout
|
|
271
|
-
* (`i18n/{language}.json` — files in `public/i18n/`, served from the site
|
|
272
|
-
* root — unless the consumer overrides the path).
|
|
273
|
-
* The descriptor still code-splits: the fetch implementation loads only on
|
|
274
|
-
* first resolve.
|
|
275
|
-
*/
|
|
276
|
-
private readonly _getLoader;
|
|
277
|
-
private _resolvedLoader;
|
|
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;
|
|
285
|
-
private readonly _inflight;
|
|
286
|
-
/**
|
|
287
|
-
* Out-of-order safety: a response reaches the visible signals only when it
|
|
288
|
-
* belongs to the currently intended language (`_currentLanguageId()`).
|
|
289
|
-
* Everything else stays cached. (A monotonic request token used to guard
|
|
290
|
-
* this, but it over-constrained legitimate same-language loads.)
|
|
291
|
-
*/
|
|
292
|
-
private _applyCount;
|
|
335
|
+
private readonly _languageStorage;
|
|
336
|
+
private readonly _currentLanguageId;
|
|
337
|
+
private readonly _store;
|
|
293
338
|
private _initialized;
|
|
294
339
|
private readonly _tasks;
|
|
295
|
-
readonly languageChanged: Signal<L>;
|
|
296
340
|
readonly languages: Signal<readonly Language<L>[]>;
|
|
297
341
|
readonly currentLanguage: Signal<L>;
|
|
298
342
|
readonly currentLanguageObject: Signal<Language<L>>;
|
|
299
343
|
readonly dir: Signal<Direction>;
|
|
300
344
|
readonly isRtl: Signal<boolean>;
|
|
301
|
-
private readonly _loadingState;
|
|
302
|
-
private readonly _loadingError;
|
|
303
345
|
/** Loader state for skeletons/spinners. */
|
|
304
|
-
readonly loadingState: Signal<"
|
|
346
|
+
readonly loadingState: Signal<"idle" | "loading" | "error">;
|
|
305
347
|
readonly loadingError: Signal<unknown>;
|
|
306
348
|
readonly isLoading: Signal<boolean>;
|
|
307
349
|
private readonly _ready;
|
|
@@ -315,11 +357,7 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
315
357
|
* Missing-key reporting. `warnOnMissingKey` defaults to dev-mode warnings
|
|
316
358
|
* unless the consumer supplied a handler (then the handler owns reporting).
|
|
317
359
|
*/
|
|
318
|
-
private readonly
|
|
319
|
-
private readonly _missingKeys;
|
|
320
|
-
private readonly _reportedMissingKeys;
|
|
321
|
-
private readonly _pendingMissingKeys;
|
|
322
|
-
private _missingFlushQueued;
|
|
360
|
+
private readonly _missingKeyReporter;
|
|
323
361
|
/**
|
|
324
362
|
* Keys that could not be resolved from the current dictionary, the fallback
|
|
325
363
|
* dictionary, or a `defaultValue`, in the order they were first looked up.
|
|
@@ -329,6 +367,8 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
329
367
|
readonly missingKeys: Signal<readonly string[]>;
|
|
330
368
|
/** Resets the report (and the once-per-key dedupe), e.g. after a fix. */
|
|
331
369
|
clearMissingKeys(): void;
|
|
370
|
+
/** Resets the missing-parameter dedupe, e.g. after adding the argument. */
|
|
371
|
+
clearMissingParams(): void;
|
|
332
372
|
constructor();
|
|
333
373
|
getLanguage(id: L): Language<L> | undefined;
|
|
334
374
|
/**
|
|
@@ -354,11 +394,9 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
354
394
|
t(key: RegisteredI18nKey, params: TranslateParams | (() => TranslateParams)): Signal<string>;
|
|
355
395
|
t(key: RegisteredI18nKey, defaultValue: string, params?: TranslateParams | (() => TranslateParams)): Signal<string>;
|
|
356
396
|
private _resolveKeyText;
|
|
357
|
-
loadedTranslations: Signal<Record<string, unknown>>;
|
|
397
|
+
readonly loadedTranslations: Signal<Record<string, unknown>>;
|
|
358
398
|
/** Preload without switching (use in `APP_INITIALIZER` / route guards). */
|
|
359
|
-
loadTranslations(languageId: L,
|
|
360
|
-
silent?: boolean;
|
|
361
|
-
}): Promise<Record<string, unknown>>;
|
|
399
|
+
loadTranslations(languageId: L): Promise<Record<string, unknown>>;
|
|
362
400
|
/**
|
|
363
401
|
* Invalidates cached dictionaries and reloads them from the loader.
|
|
364
402
|
*
|
|
@@ -376,9 +414,12 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
376
414
|
* `onLoadError` exactly like `loadTranslations`.
|
|
377
415
|
*/
|
|
378
416
|
reload(languageId?: L): Promise<boolean>;
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
417
|
+
/**
|
|
418
|
+
* Flips between the first two configured languages. Documentation and
|
|
419
|
+
* templates commonly place it next to `next()`/`previous()`, so it warns in
|
|
420
|
+
* dev mode when more than two languages are configured — use the cycling
|
|
421
|
+
* methods there.
|
|
422
|
+
*/
|
|
382
423
|
toggle(): void;
|
|
383
424
|
next(): void;
|
|
384
425
|
previous(): void;
|
|
@@ -392,9 +433,7 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
392
433
|
formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
|
|
393
434
|
/** BCP-47 locale driving Intl + ICU plural rules (falls back to the id). */
|
|
394
435
|
readonly locale: Signal<string>;
|
|
395
|
-
private readonly
|
|
396
|
-
private numberFormatter;
|
|
397
|
-
private dateTimeFormatter;
|
|
436
|
+
private readonly _messageFormatter;
|
|
398
437
|
private applyLanguage;
|
|
399
438
|
private render;
|
|
400
439
|
/**
|
|
@@ -404,32 +443,23 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
404
443
|
*/
|
|
405
444
|
private _lookupKey;
|
|
406
445
|
private _localeOf;
|
|
407
|
-
/** Loads the fallback in the background when it is not cached yet. */
|
|
408
|
-
private _ensureFallback;
|
|
409
446
|
private _hasDictionary;
|
|
410
447
|
/**
|
|
411
448
|
* Records a key no dictionary could resolve. Once per key per session; the
|
|
412
|
-
*
|
|
413
|
-
* `computed` (Angular forbids signal writes inside a computation).
|
|
449
|
+
* reporter defers the signal write so `t()` can stay a pure `computed`.
|
|
414
450
|
*/
|
|
415
451
|
private _reportMissingKey;
|
|
416
|
-
private _queueMissingFlush;
|
|
417
|
-
private _loadTranslations;
|
|
418
452
|
/**
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
453
|
+
* Mirrors `_reportMissingKey` for absent message arguments. The output keeps
|
|
454
|
+
* the placeholder; this only records/warns, once per (key, param) pair. The
|
|
455
|
+
* hook is deferred to a microtask for the same NG0600 reason.
|
|
456
|
+
*/
|
|
457
|
+
private _reportMissingParam;
|
|
458
|
+
/**
|
|
459
|
+
* Exact key first, then the nested walk. Exports from some tools keep the
|
|
460
|
+
* dot in the key (`{ "app.title": "x" }`); on a collision the flat key wins.
|
|
422
461
|
*/
|
|
423
|
-
private _readStored;
|
|
424
|
-
/** Persists the language. Server never writes (response cookies are app-owned). */
|
|
425
|
-
private _writeStored;
|
|
426
|
-
private transferKey;
|
|
427
|
-
/** Consumes server-rendered dictionaries so the client never refetches. */
|
|
428
|
-
private readTransfer;
|
|
429
|
-
/** Stores freshly loaded dictionaries for hydration (server only). */
|
|
430
|
-
private writeTransfer;
|
|
431
462
|
private _resolveKey;
|
|
432
|
-
private _resolveInitialLanguage;
|
|
433
463
|
static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaI18n<any>, never>;
|
|
434
464
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
435
465
|
}
|
|
@@ -448,6 +478,16 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
448
478
|
* ],
|
|
449
479
|
* })
|
|
450
480
|
* ```
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```ts
|
|
484
|
+
* const AR = { id: 'ar', nativeName: 'العربية', dir: 'rtl' };
|
|
485
|
+
* const EN = { id: 'en', nativeName: 'English', dir: 'ltr' };
|
|
486
|
+
* provideRiviniaI18n({
|
|
487
|
+
* defaultLanguage: 'ar',
|
|
488
|
+
* languages: [AR, EN],
|
|
489
|
+
* })
|
|
490
|
+
* ```
|
|
451
491
|
*/
|
|
452
492
|
export declare function provideRiviniaI18n<L extends string>(config: RiviniaI18nConfig<L>): EnvironmentProviders;
|
|
453
493
|
/** Shorthand for `inject(RiviniaI18n)` — preserves the configured language union. */
|
|
@@ -476,7 +516,11 @@ export declare function defineRiviniaI18n<L extends string>(config: RiviniaI18nC
|
|
|
476
516
|
provide: () => EnvironmentProviders;
|
|
477
517
|
inject: () => RiviniaI18n<L>;
|
|
478
518
|
};
|
|
479
|
-
/**
|
|
519
|
+
/**
|
|
520
|
+
* Progressive-enhancement wrapper around the View Transition API.
|
|
521
|
+
* @internal Driven by `RiviniaI18n`; consumers configure
|
|
522
|
+
* `viewTransition` instead of injecting this service.
|
|
523
|
+
*/
|
|
480
524
|
export declare class ViewTransitionService {
|
|
481
525
|
private readonly _doc;
|
|
482
526
|
run(callback: () => void): void;
|
|
@@ -491,12 +535,12 @@ export declare class ViewTransitionService {
|
|
|
491
535
|
* lists prefer `translate()` in component code — or `t()`, which returns a
|
|
492
536
|
* signal a template can read without re-running the pipe.
|
|
493
537
|
*/
|
|
494
|
-
export declare class
|
|
538
|
+
export declare class RvTranslatePipe<L extends string = string> {
|
|
495
539
|
private readonly _i18n;
|
|
496
540
|
transform(key: RegisteredI18nKey, defaultValue?: string, params?: TranslateParams): string;
|
|
497
541
|
transform(key: RegisteredI18nKey, params?: TranslateParams): string;
|
|
498
542
|
transform(translations: Translation<L>): string;
|
|
499
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<
|
|
500
|
-
static ɵpipe: i0.ɵɵPipeDeclaration<
|
|
543
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RvTranslatePipe<any>, never>;
|
|
544
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<RvTranslatePipe<any>, "rvTranslate", true>;
|
|
501
545
|
}
|
|
502
|
-
export type { Direction, HttpLoaderOptions, Language, LoaderContext, LoaderDescriptor, MissingKeyEvent, RegisteredI18nKey, RemoteLoaderOptions, RiviniaI18nConfig, RiviniaI18nKeyRegistry, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|
|
546
|
+
export type { Direction, HttpLoaderOptions, IcuFormatOptions, Language, LoaderContext, LoaderDescriptor, MissingKeyEvent, MissingParamEvent, RegisteredI18nKey, RemoteLoaderOptions, RiviniaI18nConfig, RiviniaI18nKeyRegistry, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { t as resolveLoaderUrl } from "./rivinia-i18n-loader-url-B9SlR1XB.mjs";
|
|
2
|
-
var HttpLoader = class {
|
|
3
|
-
_options;
|
|
4
|
-
constructor(_options) {
|
|
5
|
-
this._options = _options;
|
|
6
|
-
}
|
|
7
|
-
async load(language, context) {
|
|
8
|
-
const built = this._options.buildUrl?.(language) ?? `${this._options.endpoint}/${language}`;
|
|
9
|
-
const url = resolveLoaderUrl(built, context);
|
|
10
|
-
const response = await fetch(url, { method: this._options.method ?? "GET" });
|
|
11
|
-
if (!response.ok) throw new Error(`[rivinia/i18n] Failed to load "${url}": ${response.statusText}`);
|
|
12
|
-
return response.json();
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
export { HttpLoader };
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=rivinia-i18n-http-loader.impl--BRii7w1.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-http-loader.impl--BRii7w1.mjs","names":[],"sources":["../../../projects/i18n/src/lib/services/http-loader.impl.ts"],"sourcesContent":["import type { HttpLoaderOptions, LoaderContext, TranslationLoader } from '../models/loaders';\nimport { resolveLoaderUrl } from '../utils/loader-url';\n\nexport class HttpLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options: HttpLoaderOptions) {}\n\n async load(language: L, context?: LoaderContext): Promise<Record<string, unknown>> {\n const built = this._options.buildUrl?.(language) ?? `${this._options.endpoint}/${language}`;\n const url = resolveLoaderUrl(built, context);\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":";AAGA,IAAa,aAAb,MAAuB;CACQ;CAA7B,YAA6B,UAA2B;EAA3B,KAAA,WAAA;CAA8B;CAE3D,MAAM,KAAK,UAAa,SAAuB;EAC7C,MAAM,QAAQ,KAAK,SAAS,WAAW,QAAQ,KAAK,GAAG,KAAK,SAAS,SAAQ,GAAI;EACjF,MAAM,MAAM,iBAAiB,OAAO,OAAO;EAC3C,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,18 +0,0 @@
|
|
|
1
|
-
import { t as resolveLoaderUrl } from "./rivinia-i18n-loader-url-B9SlR1XB.mjs";
|
|
2
|
-
const DEFAULT_BASE_PATH = "i18n";
|
|
3
|
-
var JsonLoader = class {
|
|
4
|
-
_options;
|
|
5
|
-
constructor(_options) {
|
|
6
|
-
this._options = _options;
|
|
7
|
-
}
|
|
8
|
-
async load(language, context) {
|
|
9
|
-
const basePath = this._options?.path ?? DEFAULT_BASE_PATH;
|
|
10
|
-
const url = resolveLoaderUrl(`${basePath}/${language}.json`, context);
|
|
11
|
-
const response = await fetch(url);
|
|
12
|
-
if (!response.ok) throw new Error(`[rivinia/i18n] Failed to load "${url}": ${response.statusText}`);
|
|
13
|
-
return response.json();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
export { JsonLoader };
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=rivinia-i18n-json-loader.impl-Bq-W-UW9.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-json-loader.impl-Bq-W-UW9.mjs","names":[],"sources":["../../../projects/i18n/src/lib/services/json-loader.impl.ts"],"sourcesContent":["import type { LoaderContext, TranslationLoader } from '../models/loaders';\nimport { resolveLoaderUrl } from '../utils/loader-url';\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, context?: LoaderContext): Promise<Record<string, unknown>> {\n const basePath = this._options?.path ?? DEFAULT_BASE_PATH;\n const url = resolveLoaderUrl(`${basePath}/${language}.json`, context);\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":";AAGA,MAAM,oBAAoB;AAE1B,IAAa,aAAb,MAAuB;CACQ;CAA7B,YAA6B,UAA4B;EAA5B,KAAA,WAAA;CAA+B;CAE5D,MAAM,KAAK,UAAa,SAAuB;EAC7C,MAAM,WAAW,KAAK,UAAU,QAAQ;EACxC,MAAM,MAAM,iBAAiB,GAAG,SAAQ,GAAI,SAAQ,QAAS,OAAO;EACpE,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,11 +0,0 @@
|
|
|
1
|
-
function resolveLoaderUrl(url, context) {
|
|
2
|
-
if (!context?.isServer) return url;
|
|
3
|
-
try {
|
|
4
|
-
return new URL(url, context.baseUrl).href;
|
|
5
|
-
} catch {
|
|
6
|
-
return url;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export { resolveLoaderUrl as t };
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=rivinia-i18n-loader-url-B9SlR1XB.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-loader-url-B9SlR1XB.mjs","names":[],"sources":["../../../projects/i18n/src/lib/utils/loader-url.ts"],"sourcesContent":["import type { LoaderContext } from '../models/loaders';\n\n/**\n * Resolves a loader URL for the current platform.\n *\n * The browser already resolves a relative `fetch()` URL against\n * `document.baseURI`, so the string is passed through untouched (a consumer's\n * `fetch` mock keeps seeing the same URL it always saw). On the server there\n * is no document, so a relative URL is resolved against `context.baseUrl`.\n *\n * Absolute URLs are never rewritten, and a base that cannot be parsed leaves\n * the input unchanged — a loader must not throw while building a URL.\n */\nexport function resolveLoaderUrl(url: string, context?: LoaderContext): string {\n if (!context?.isServer) return url;\n try {\n return new URL(url, context.baseUrl).href;\n } catch {\n return url;\n }\n}\n"],"mappings":"AAaA,SAAgB,iBAAiB,KAAa,SAAuB;CACnE,IAAI,CAAC,SAAS,UAAU,OAAO;CAC/B,IAAI;EACF,OAAO,IAAI,IAAI,KAAK,QAAQ,OAAO,CAAC,CAAC;CACvC,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { t as resolveLoaderUrl } from "./rivinia-i18n-loader-url-B9SlR1XB.mjs";
|
|
2
|
-
var RemoteLoader = class {
|
|
3
|
-
_options;
|
|
4
|
-
constructor(_options) {
|
|
5
|
-
this._options = _options;
|
|
6
|
-
}
|
|
7
|
-
async load(language, context) {
|
|
8
|
-
const url = resolveLoaderUrl(this._options.url(language), context);
|
|
9
|
-
const response = await fetch(url, { headers: this._options.headers });
|
|
10
|
-
if (!response.ok) throw new Error(`[rivinia/i18n] Failed to load "${url}": ${response.statusText}`);
|
|
11
|
-
return response.json();
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
export { RemoteLoader };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=rivinia-i18n-remote-loader.impl-CqKS6JWN.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rivinia-i18n-remote-loader.impl-CqKS6JWN.mjs","names":[],"sources":["../../../projects/i18n/src/lib/services/remote-loader.impl.ts"],"sourcesContent":["import type { LoaderContext, RemoteLoaderOptions, TranslationLoader } from '../models/loaders';\nimport { resolveLoaderUrl } from '../utils/loader-url';\n\nexport class RemoteLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options: RemoteLoaderOptions) {}\n\n async load(language: L, context?: LoaderContext): Promise<Record<string, unknown>> {\n const url = resolveLoaderUrl(this._options.url(language), context);\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":";AAGA,IAAa,eAAb,MAAyB;CACM;CAA7B,YAA6B,UAA6B;EAA7B,KAAA,WAAA;CAAgC;CAE7D,MAAM,KAAK,UAAa,SAAuB;EAC7C,MAAM,MAAM,iBAAiB,KAAK,SAAS,IAAI,QAAQ,GAAG,OAAO;EACjE,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"}
|