@rivinia/i18n 0.5.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.
@@ -230,7 +230,7 @@ export declare class RiviniaLoadError extends Error {
230
230
  * ``i18n.translate(`status.${code}` as RegisteredI18nKey)``.
231
231
  */
232
232
  interface RiviniaI18nKeyRegistry {}
233
- /** Every key accepted by `translate()`, `t()` and `RTranslatePipe`. */
233
+ /** Every key accepted by `translate()`, `t()` and the `rvTranslate` pipe. */
234
234
  type RegisteredI18nKey = RiviniaI18nKeyRegistry extends {
235
235
  keys: infer K extends string;
236
236
  } ? K : string;
@@ -311,11 +311,7 @@ export declare function formatIcu(template: string, params: TranslateParams, loc
311
311
  export declare class RiviniaI18n<L extends string = string> {
312
312
  private readonly _config;
313
313
  private readonly _viewTransition;
314
- private readonly _storageKey;
315
- private readonly _storageStrategy;
316
314
  private readonly _autoApplyDirection;
317
- /** Writes reach storage/cookies only after an explicit switch (RIV-17). */
318
- private readonly _persist;
319
315
  /** Validated once; `null` means no fallback chain. */
320
316
  private readonly _fallbackId;
321
317
  /**
@@ -327,61 +323,25 @@ export declare class RiviniaI18n<L extends string = string> {
327
323
  /** Present only on the server: used for cookie reads + transfer writes. */
328
324
  private readonly _request;
329
325
  private readonly _transfer;
326
+ private readonly _direction;
330
327
  /**
331
328
  * Platform facts for loaders, built once: `REQUEST` + `<base href>` on the
332
329
  * server, `document.baseURI` in the browser. This is what makes the default
333
330
  * loader work under SSR instead of fetching a relative URL Node cannot parse.
334
331
  */
335
332
  readonly loaderContext: LoaderContext;
336
- private readonly _currentLanguageId;
333
+ /** Declared before the storage collaborator: it reads this during setup. */
337
334
  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
- /**
346
- * Explicit loader wins; otherwise the conventional JSON layout
347
- * (`i18n/{language}.json` — files in `public/i18n/`, served from the site
348
- * root — unless the consumer overrides the path).
349
- * The descriptor still code-splits: the fetch implementation loads only on
350
- * first resolve.
351
- */
352
- private readonly _getLoader;
353
- private _resolvedLoader;
354
- private readonly _translationsCache;
355
- /**
356
- * Per-language generation, bumped by `reload()`. A load captures the
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;
364
- /**
365
- * Out-of-order safety: a response reaches the visible signals only when it
366
- * belongs to the currently intended language (`_currentLanguageId()`).
367
- * Everything else stays cached. (A monotonic request token used to guard
368
- * this, but it over-constrained legitimate same-language loads.)
369
- */
370
- private _applyCount;
335
+ private readonly _languageStorage;
336
+ private readonly _currentLanguageId;
337
+ private readonly _store;
371
338
  private _initialized;
372
339
  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
340
  readonly languages: Signal<readonly Language<L>[]>;
379
341
  readonly currentLanguage: Signal<L>;
380
342
  readonly currentLanguageObject: Signal<Language<L>>;
381
343
  readonly dir: Signal<Direction>;
382
344
  readonly isRtl: Signal<boolean>;
383
- private readonly _loadingState;
384
- private readonly _loadingError;
385
345
  /** Loader state for skeletons/spinners. */
386
346
  readonly loadingState: Signal<"idle" | "loading" | "error">;
387
347
  readonly loadingError: Signal<unknown>;
@@ -397,17 +357,7 @@ export declare class RiviniaI18n<L extends string = string> {
397
357
  * Missing-key reporting. `warnOnMissingKey` defaults to dev-mode warnings
398
358
  * unless the consumer supplied a handler (then the handler owns reporting).
399
359
  */
400
- private readonly _warnOnMissingKey;
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;
360
+ private readonly _missingKeyReporter;
411
361
  /**
412
362
  * Keys that could not be resolved from the current dictionary, the fallback
413
363
  * dictionary, or a `defaultValue`, in the order they were first looked up.
@@ -444,11 +394,9 @@ export declare class RiviniaI18n<L extends string = string> {
444
394
  t(key: RegisteredI18nKey, params: TranslateParams | (() => TranslateParams)): Signal<string>;
445
395
  t(key: RegisteredI18nKey, defaultValue: string, params?: TranslateParams | (() => TranslateParams)): Signal<string>;
446
396
  private _resolveKeyText;
447
- loadedTranslations: Signal<Record<string, unknown>>;
397
+ readonly loadedTranslations: Signal<Record<string, unknown>>;
448
398
  /** Preload without switching (use in `APP_INITIALIZER` / route guards). */
449
- loadTranslations(languageId: L, opts?: {
450
- silent?: boolean;
451
- }): Promise<Record<string, unknown>>;
399
+ loadTranslations(languageId: L): Promise<Record<string, unknown>>;
452
400
  /**
453
401
  * Invalidates cached dictionaries and reloads them from the loader.
454
402
  *
@@ -466,9 +414,6 @@ export declare class RiviniaI18n<L extends string = string> {
466
414
  * `onLoadError` exactly like `loadTranslations`.
467
415
  */
468
416
  reload(languageId?: L): Promise<boolean>;
469
- private _reloadOne;
470
- private _generationOf;
471
- private _invalidate;
472
417
  /**
473
418
  * Flips between the first two configured languages. Documentation and
474
419
  * templates commonly place it next to `next()`/`previous()`, so it warns in
@@ -488,11 +433,8 @@ export declare class RiviniaI18n<L extends string = string> {
488
433
  formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
489
434
  /** BCP-47 locale driving Intl + ICU plural rules (falls back to the id). */
490
435
  readonly locale: Signal<string>;
491
- private readonly _formatters;
492
- private numberFormatter;
493
- private dateTimeFormatter;
436
+ private readonly _messageFormatter;
494
437
  private applyLanguage;
495
- private _persistLanguage;
496
438
  private render;
497
439
  /**
498
440
  * Current dictionary first, then the fallback dictionary. The returned
@@ -501,51 +443,23 @@ export declare class RiviniaI18n<L extends string = string> {
501
443
  */
502
444
  private _lookupKey;
503
445
  private _localeOf;
504
- /** Loads the fallback in the background when it is not cached yet. */
505
- private _ensureFallback;
506
446
  private _hasDictionary;
507
447
  /**
508
448
  * Records a key no dictionary could resolve. Once per key per session; the
509
- * signal write is deferred to a microtask so `t()` can stay a pure
510
- * `computed` (Angular forbids signal writes inside a computation).
449
+ * reporter defers the signal write so `t()` can stay a pure `computed`.
511
450
  */
512
451
  private _reportMissingKey;
513
- private _queueMissingFlush;
514
452
  /**
515
453
  * Mirrors `_reportMissingKey` for absent message arguments. The output keeps
516
454
  * the placeholder; this only records/warns, once per (key, param) pair. The
517
455
  * hook is deferred to a microtask for the same NG0600 reason.
518
456
  */
519
457
  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
458
  /**
544
459
  * Exact key first, then the nested walk. Exports from some tools keep the
545
460
  * dot in the key (`{ "app.title": "x" }`); on a collision the flat key wins.
546
461
  */
547
462
  private _resolveKey;
548
- private _resolveInitialLanguage;
549
463
  static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaI18n<any>, never>;
550
464
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
551
465
  }
@@ -564,6 +478,16 @@ export declare class RiviniaI18n<L extends string = string> {
564
478
  * ],
565
479
  * })
566
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
+ * ```
567
491
  */
568
492
  export declare function provideRiviniaI18n<L extends string>(config: RiviniaI18nConfig<L>): EnvironmentProviders;
569
493
  /** Shorthand for `inject(RiviniaI18n)` — preserves the configured language union. */
@@ -611,12 +535,12 @@ export declare class ViewTransitionService {
611
535
  * lists prefer `translate()` in component code — or `t()`, which returns a
612
536
  * signal a template can read without re-running the pipe.
613
537
  */
614
- export declare class RTranslatePipe<L extends string = string> {
538
+ export declare class RvTranslatePipe<L extends string = string> {
615
539
  private readonly _i18n;
616
540
  transform(key: RegisteredI18nKey, defaultValue?: string, params?: TranslateParams): string;
617
541
  transform(key: RegisteredI18nKey, params?: TranslateParams): string;
618
542
  transform(translations: Translation<L>): string;
619
- static ɵfac: i0.ɵɵFactoryDeclaration<RTranslatePipe<any>, never>;
620
- static ɵpipe: i0.ɵɵPipeDeclaration<RTranslatePipe<any>, "rTranslate", true>;
543
+ static ɵfac: i0.ɵɵFactoryDeclaration<RvTranslatePipe<any>, never>;
544
+ static ɵpipe: i0.ɵɵPipeDeclaration<RvTranslatePipe<any>, "rvTranslate", true>;
621
545
  }
622
546
  export type { Direction, HttpLoaderOptions, IcuFormatOptions, Language, LoaderContext, LoaderDescriptor, MissingKeyEvent, MissingParamEvent, RegisteredI18nKey, RemoteLoaderOptions, RiviniaI18nConfig, RiviniaI18nKeyRegistry, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };