@rivinia/i18n 0.4.0 → 0.5.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 +103 -0
- package/README.md +73 -7
- 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 +464 -187
- package/fesm2022/rivinia-i18n.mjs.map +1 -1
- package/package.json +22 -1
- package/types/rivinia-i18n.d.ts +130 -10
- 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.
|
|
@@ -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.
|
|
@@ -240,6 +314,8 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
240
314
|
private readonly _storageKey;
|
|
241
315
|
private readonly _storageStrategy;
|
|
242
316
|
private readonly _autoApplyDirection;
|
|
317
|
+
/** Writes reach storage/cookies only after an explicit switch (RIV-17). */
|
|
318
|
+
private readonly _persist;
|
|
243
319
|
/** Validated once; `null` means no fallback chain. */
|
|
244
320
|
private readonly _fallbackId;
|
|
245
321
|
/**
|
|
@@ -283,6 +359,8 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
283
359
|
*/
|
|
284
360
|
private readonly _generations;
|
|
285
361
|
private readonly _inflight;
|
|
362
|
+
/** Non-background loads in flight; `loadingState` follows this count. */
|
|
363
|
+
private _loadingCount;
|
|
286
364
|
/**
|
|
287
365
|
* Out-of-order safety: a response reaches the visible signals only when it
|
|
288
366
|
* belongs to the currently intended language (`_currentLanguageId()`).
|
|
@@ -292,6 +370,10 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
292
370
|
private _applyCount;
|
|
293
371
|
private _initialized;
|
|
294
372
|
private readonly _tasks;
|
|
373
|
+
/**
|
|
374
|
+
* @deprecated Use `currentLanguage`, which is the same signal.
|
|
375
|
+
* Scheduled for removal before 1.0.
|
|
376
|
+
*/
|
|
295
377
|
readonly languageChanged: Signal<L>;
|
|
296
378
|
readonly languages: Signal<readonly Language<L>[]>;
|
|
297
379
|
readonly currentLanguage: Signal<L>;
|
|
@@ -301,7 +383,7 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
301
383
|
private readonly _loadingState;
|
|
302
384
|
private readonly _loadingError;
|
|
303
385
|
/** Loader state for skeletons/spinners. */
|
|
304
|
-
readonly loadingState: Signal<"
|
|
386
|
+
readonly loadingState: Signal<"idle" | "loading" | "error">;
|
|
305
387
|
readonly loadingError: Signal<unknown>;
|
|
306
388
|
readonly isLoading: Signal<boolean>;
|
|
307
389
|
private readonly _ready;
|
|
@@ -319,7 +401,13 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
319
401
|
private readonly _missingKeys;
|
|
320
402
|
private readonly _reportedMissingKeys;
|
|
321
403
|
private readonly _pendingMissingKeys;
|
|
404
|
+
private readonly _pendingMissingEvents;
|
|
322
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;
|
|
323
411
|
/**
|
|
324
412
|
* Keys that could not be resolved from the current dictionary, the fallback
|
|
325
413
|
* dictionary, or a `defaultValue`, in the order they were first looked up.
|
|
@@ -329,6 +417,8 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
329
417
|
readonly missingKeys: Signal<readonly string[]>;
|
|
330
418
|
/** Resets the report (and the once-per-key dedupe), e.g. after a fix. */
|
|
331
419
|
clearMissingKeys(): void;
|
|
420
|
+
/** Resets the missing-parameter dedupe, e.g. after adding the argument. */
|
|
421
|
+
clearMissingParams(): void;
|
|
332
422
|
constructor();
|
|
333
423
|
getLanguage(id: L): Language<L> | undefined;
|
|
334
424
|
/**
|
|
@@ -379,6 +469,12 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
379
469
|
private _reloadOne;
|
|
380
470
|
private _generationOf;
|
|
381
471
|
private _invalidate;
|
|
472
|
+
/**
|
|
473
|
+
* Flips between the first two configured languages. Documentation and
|
|
474
|
+
* templates commonly place it next to `next()`/`previous()`, so it warns in
|
|
475
|
+
* dev mode when more than two languages are configured — use the cycling
|
|
476
|
+
* methods there.
|
|
477
|
+
*/
|
|
382
478
|
toggle(): void;
|
|
383
479
|
next(): void;
|
|
384
480
|
previous(): void;
|
|
@@ -396,6 +492,7 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
396
492
|
private numberFormatter;
|
|
397
493
|
private dateTimeFormatter;
|
|
398
494
|
private applyLanguage;
|
|
495
|
+
private _persistLanguage;
|
|
399
496
|
private render;
|
|
400
497
|
/**
|
|
401
498
|
* Current dictionary first, then the fallback dictionary. The returned
|
|
@@ -414,7 +511,22 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
414
511
|
*/
|
|
415
512
|
private _reportMissingKey;
|
|
416
513
|
private _queueMissingFlush;
|
|
514
|
+
/**
|
|
515
|
+
* Mirrors `_reportMissingKey` for absent message arguments. The output keeps
|
|
516
|
+
* the placeholder; this only records/warns, once per (key, param) pair. The
|
|
517
|
+
* hook is deferred to a microtask for the same NG0600 reason.
|
|
518
|
+
*/
|
|
519
|
+
private _reportMissingParam;
|
|
520
|
+
private _queueMissingParamsFlush;
|
|
417
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;
|
|
418
530
|
/**
|
|
419
531
|
* Reads the persisted language. Cookie strategy: server reads the request
|
|
420
532
|
* `Cookie` header (no hydration mismatch), browser reads `document.cookie`.
|
|
@@ -428,6 +540,10 @@ export declare class RiviniaI18n<L extends string = string> {
|
|
|
428
540
|
private readTransfer;
|
|
429
541
|
/** Stores freshly loaded dictionaries for hydration (server only). */
|
|
430
542
|
private writeTransfer;
|
|
543
|
+
/**
|
|
544
|
+
* Exact key first, then the nested walk. Exports from some tools keep the
|
|
545
|
+
* dot in the key (`{ "app.title": "x" }`); on a collision the flat key wins.
|
|
546
|
+
*/
|
|
431
547
|
private _resolveKey;
|
|
432
548
|
private _resolveInitialLanguage;
|
|
433
549
|
static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaI18n<any>, never>;
|
|
@@ -476,7 +592,11 @@ export declare function defineRiviniaI18n<L extends string>(config: RiviniaI18nC
|
|
|
476
592
|
provide: () => EnvironmentProviders;
|
|
477
593
|
inject: () => RiviniaI18n<L>;
|
|
478
594
|
};
|
|
479
|
-
/**
|
|
595
|
+
/**
|
|
596
|
+
* Progressive-enhancement wrapper around the View Transition API.
|
|
597
|
+
* @internal Driven by `RiviniaI18n`; consumers configure
|
|
598
|
+
* `viewTransition` instead of injecting this service.
|
|
599
|
+
*/
|
|
480
600
|
export declare class ViewTransitionService {
|
|
481
601
|
private readonly _doc;
|
|
482
602
|
run(callback: () => void): void;
|
|
@@ -499,4 +619,4 @@ export declare class RTranslatePipe<L extends string = string> {
|
|
|
499
619
|
static ɵfac: i0.ɵɵFactoryDeclaration<RTranslatePipe<any>, never>;
|
|
500
620
|
static ɵpipe: i0.ɵɵPipeDeclaration<RTranslatePipe<any>, "rTranslate", true>;
|
|
501
621
|
}
|
|
502
|
-
export type { Direction, HttpLoaderOptions, Language, LoaderContext, LoaderDescriptor, MissingKeyEvent, RegisteredI18nKey, RemoteLoaderOptions, RiviniaI18nConfig, RiviniaI18nKeyRegistry, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|
|
622
|
+
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"}
|