@jsverse/transloco 7.5.0 → 7.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +34 -16
  2. package/README.md +27 -23
  3. package/esm2022/index.mjs +2 -1
  4. package/esm2022/lib/helpers.mjs +34 -6
  5. package/esm2022/lib/loader-component.component.mjs +3 -3
  6. package/esm2022/lib/transloco-fallback-strategy.mjs +7 -5
  7. package/esm2022/lib/transloco-lang.mjs +2 -2
  8. package/esm2022/lib/transloco-loading-template.mjs +4 -2
  9. package/esm2022/lib/transloco-missing-handler.mjs +7 -5
  10. package/esm2022/lib/transloco-scope.mjs +2 -2
  11. package/esm2022/lib/transloco-testing.module.mjs +7 -7
  12. package/esm2022/lib/transloco.config.mjs +2 -2
  13. package/esm2022/lib/transloco.directive.mjs +3 -3
  14. package/esm2022/lib/transloco.interceptor.mjs +5 -5
  15. package/esm2022/lib/transloco.loader.mjs +2 -2
  16. package/esm2022/lib/transloco.module.mjs +4 -4
  17. package/esm2022/lib/transloco.pipe.mjs +3 -3
  18. package/esm2022/lib/transloco.service.mjs +18 -14
  19. package/esm2022/lib/transloco.signal.mjs +99 -0
  20. package/esm2022/lib/transloco.transpiler.mjs +9 -9
  21. package/esm2022/lib/types.mjs +1 -1
  22. package/fesm2022/jsverse-transloco.mjs +197 -65
  23. package/fesm2022/jsverse-transloco.mjs.map +1 -1
  24. package/index.d.ts +1 -0
  25. package/lib/helpers.d.ts +2 -2
  26. package/lib/transloco.service.d.ts +2 -3
  27. package/lib/transloco.signal.d.ts +39 -0
  28. package/lib/types.d.ts +4 -0
  29. package/package.json +2 -3
  30. package/schematics/src/component/index.js +1 -1
  31. package/schematics/src/component/index.js.map +1 -1
  32. package/schematics/src/join/index.js +1 -1
  33. package/schematics/src/join/index.js.map +1 -1
  34. package/schematics/src/keys-manager/index.js +3 -4
  35. package/schematics/src/keys-manager/index.js.map +1 -1
  36. package/schematics/src/migrate/index.js +1 -1
  37. package/schematics/src/migrate/index.js.map +1 -1
  38. package/schematics/src/migrate/ngx-translate-migration.js +2 -2
  39. package/schematics/src/migrate/ngx-translate-migration.js.map +1 -1
  40. package/schematics/src/ng-add/generators/http-loader.gen.js +1 -2
  41. package/schematics/src/ng-add/generators/http-loader.gen.js.map +1 -1
  42. package/schematics/src/ng-add/generators/root-module.gen.js +1 -2
  43. package/schematics/src/ng-add/generators/root-module.gen.js.map +1 -1
  44. package/schematics/src/ng-add/generators/translation-files.gen.js +3 -4
  45. package/schematics/src/ng-add/generators/translation-files.gen.js.map +1 -1
  46. package/schematics/src/ng-add/index.js +1 -1
  47. package/schematics/src/ng-add/index.js.map +1 -1
  48. package/schematics/src/ng-migrate/index.js +1 -1
  49. package/schematics/src/ng-migrate/index.js.map +1 -1
  50. package/schematics/src/ng-migrate/ng-migrate.js +1 -2
  51. package/schematics/src/ng-migrate/ng-migrate.js.map +1 -1
  52. package/schematics/src/schematics.utils.js +2 -2
  53. package/schematics/src/schematics.utils.js.map +1 -1
  54. package/schematics/src/scope/index.js +1 -1
  55. package/schematics/src/scope/index.js.map +1 -1
  56. package/schematics/src/split/index.js +1 -1
  57. package/schematics/src/split/index.js.map +1 -1
  58. package/schematics/src/upgrade/index.js +1 -1
  59. package/schematics/src/upgrade/index.js.map +1 -1
  60. package/schematics/src/upgrade/v2.js +1 -2
  61. package/schematics/src/upgrade/v2.js.map +1 -1
  62. package/schematics/src/utils/array.js +2 -3
  63. package/schematics/src/utils/array.js.map +1 -1
  64. package/schematics/src/utils/config.js +1 -2
  65. package/schematics/src/utils/config.js.map +1 -1
  66. package/schematics/src/utils/find-module.js +4 -4
  67. package/schematics/src/utils/find-module.js.map +1 -1
  68. package/schematics/src/utils/package.js +1 -2
  69. package/schematics/src/utils/package.js.map +1 -1
  70. package/schematics/src/utils/projects.js +6 -7
  71. package/schematics/src/utils/projects.js.map +1 -1
  72. package/schematics/src/utils/translations.js +2 -3
  73. package/schematics/src/utils/translations.js.map +1 -1
  74. package/schematics/src/utils/transloco.js +11 -12
  75. package/schematics/src/utils/transloco.js.map +1 -1
@@ -1,8 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, Injectable, Injector, Inject, Optional, Component, Input, TemplateRef, DestroyRef, ChangeDetectorRef, ElementRef, ViewContainerRef, Renderer2, Directive, Pipe, NgModule, makeEnvironmentProviders, APP_INITIALIZER } from '@angular/core';
2
+ import { InjectionToken, inject, Injectable, Injector, Inject, DestroyRef, Optional, Component, Input, TemplateRef, ChangeDetectorRef, ElementRef, ViewContainerRef, Renderer2, Directive, Pipe, NgModule, makeEnvironmentProviders, APP_INITIALIZER, assertInInjectionContext, runInInjectionContext, isSignal, computed } from '@angular/core';
3
3
  import { of, take, from, map, Subject, BehaviorSubject, forkJoin, retry, tap, catchError, shareReplay, switchMap, combineLatest, EMPTY } from 'rxjs';
4
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
- import { unflatten as unflatten$1, flatten as flatten$1 } from 'flat';
4
+ import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
6
5
 
7
6
  class DefaultLoader {
8
7
  translations;
@@ -13,7 +12,7 @@ class DefaultLoader {
13
12
  return of(this.translations.get(lang) || {});
14
13
  }
15
14
  }
16
- const TRANSLOCO_LOADER = new InjectionToken('TRANSLOCO_LOADER');
15
+ const TRANSLOCO_LOADER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LOADER' : '');
17
16
 
18
17
  function getValue(obj, path) {
19
18
  if (!obj) {
@@ -108,14 +107,43 @@ function isScopeObject(item) {
108
107
  function hasInlineLoader(item) {
109
108
  return item && isObject(item.loader);
110
109
  }
111
- function unflatten(obj) {
112
- return unflatten$1(obj);
113
- }
114
110
  function flatten(obj) {
115
- return flatten$1(obj, { safe: true });
111
+ const result = {};
112
+ function recurse(curr, prop) {
113
+ if (curr === null) {
114
+ result[prop] = null;
115
+ }
116
+ else if (isObject(curr)) {
117
+ for (const [key, value] of Object.entries(curr)) {
118
+ recurse(value, prop ? `${prop}.${key}` : key);
119
+ }
120
+ }
121
+ else {
122
+ result[prop] = curr;
123
+ }
124
+ }
125
+ recurse(obj, '');
126
+ return result;
127
+ }
128
+ function unflatten(obj) {
129
+ const result = {};
130
+ for (const [key, value] of Object.entries(obj)) {
131
+ const keys = key.split('.');
132
+ let current = result;
133
+ keys.forEach((key, i) => {
134
+ if (i === keys.length - 1) {
135
+ current[key] = value;
136
+ }
137
+ else {
138
+ current[key] ??= {};
139
+ current = current[key];
140
+ }
141
+ });
142
+ }
143
+ return result;
116
144
  }
117
145
 
118
- const TRANSLOCO_CONFIG = new InjectionToken('TRANSLOCO_CONFIG', {
146
+ const TRANSLOCO_CONFIG = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_CONFIG' : '', {
119
147
  providedIn: 'root',
120
148
  factory: () => defaultConfig,
121
149
  });
@@ -158,7 +186,7 @@ function translocoConfig(config = {}) {
158
186
  };
159
187
  }
160
188
 
161
- const TRANSLOCO_TRANSPILER = new InjectionToken('TRANSLOCO_TRANSPILER');
189
+ const TRANSLOCO_TRANSPILER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_TRANSPILER' : '');
162
190
  class DefaultTranspiler {
163
191
  config = inject(TRANSLOCO_CONFIG, { optional: true }) ?? defaultConfig;
164
192
  get interpolationMatcher() {
@@ -191,7 +219,7 @@ class DefaultTranspiler {
191
219
  else if (params) {
192
220
  if (isObject(value)) {
193
221
  value = this.handleObject({
194
- value: value,
222
+ value,
195
223
  params,
196
224
  translation,
197
225
  key,
@@ -250,10 +278,10 @@ class DefaultTranspiler {
250
278
  ...rest,
251
279
  }));
252
280
  }
253
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultTranspiler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
254
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultTranspiler });
281
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultTranspiler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
282
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultTranspiler });
255
283
  }
256
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultTranspiler, decorators: [{
284
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultTranspiler, decorators: [{
257
285
  type: Injectable
258
286
  }] });
259
287
  function resolveMatcher(config) {
@@ -295,14 +323,16 @@ class FunctionalTranspiler extends DefaultTranspiler {
295
323
  }
296
324
  return super.transpile({ value: transpiled, ...rest });
297
325
  }
298
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: FunctionalTranspiler, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
299
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: FunctionalTranspiler });
326
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: FunctionalTranspiler, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
327
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: FunctionalTranspiler });
300
328
  }
301
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: FunctionalTranspiler, decorators: [{
329
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: FunctionalTranspiler, decorators: [{
302
330
  type: Injectable
303
331
  }] });
304
332
 
305
- const TRANSLOCO_MISSING_HANDLER = new InjectionToken('TRANSLOCO_MISSING_HANDLER');
333
+ const TRANSLOCO_MISSING_HANDLER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode
334
+ ? 'TRANSLOCO_MISSING_HANDLER'
335
+ : '');
306
336
  class DefaultMissingHandler {
307
337
  handle(key, config) {
308
338
  if (config.missingHandler.logMissingKey && !config.prodMode) {
@@ -311,14 +341,14 @@ class DefaultMissingHandler {
311
341
  }
312
342
  return key;
313
343
  }
314
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultMissingHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
315
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultMissingHandler });
344
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultMissingHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
345
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultMissingHandler });
316
346
  }
317
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultMissingHandler, decorators: [{
347
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultMissingHandler, decorators: [{
318
348
  type: Injectable
319
349
  }] });
320
350
 
321
- const TRANSLOCO_INTERCEPTOR = new InjectionToken('TRANSLOCO_INTERCEPTOR');
351
+ const TRANSLOCO_INTERCEPTOR = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_INTERCEPTOR' : '');
322
352
  class DefaultInterceptor {
323
353
  preSaveTranslation(translation) {
324
354
  return translation;
@@ -326,14 +356,16 @@ class DefaultInterceptor {
326
356
  preSaveTranslationKey(_, value) {
327
357
  return value;
328
358
  }
329
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
330
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultInterceptor });
359
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
360
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultInterceptor });
331
361
  }
332
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultInterceptor, decorators: [{
362
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultInterceptor, decorators: [{
333
363
  type: Injectable
334
364
  }] });
335
365
 
336
- const TRANSLOCO_FALLBACK_STRATEGY = new InjectionToken('TRANSLOCO_FALLBACK_STRATEGY');
366
+ const TRANSLOCO_FALLBACK_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode
367
+ ? 'TRANSLOCO_FALLBACK_STRATEGY'
368
+ : '');
337
369
  class DefaultFallbackStrategy {
338
370
  userConfig;
339
371
  constructor(userConfig) {
@@ -346,10 +378,10 @@ class DefaultFallbackStrategy {
346
378
  }
347
379
  return Array.isArray(fallbackLang) ? fallbackLang : [fallbackLang];
348
380
  }
349
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultFallbackStrategy, deps: [{ token: TRANSLOCO_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
350
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultFallbackStrategy });
381
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultFallbackStrategy, deps: [{ token: TRANSLOCO_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
382
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultFallbackStrategy });
351
383
  }
352
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: DefaultFallbackStrategy, decorators: [{
384
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DefaultFallbackStrategy, decorators: [{
353
385
  type: Injectable
354
386
  }], ctorParameters: () => [{ type: undefined, decorators: [{
355
387
  type: Inject,
@@ -475,6 +507,7 @@ class TranslocoService {
475
507
  events = new Subject();
476
508
  events$ = this.events.asObservable();
477
509
  config;
510
+ destroyRef = inject(DestroyRef);
478
511
  constructor(loader, parser, missingHandler, interceptor, userConfig, fallbackStrategy) {
479
512
  this.loader = loader;
480
513
  this.parser = parser;
@@ -496,11 +529,21 @@ class TranslocoService {
496
529
  /**
497
530
  * When we have a failure, we want to define the next language that succeeded as the active
498
531
  */
499
- this.events$.pipe(takeUntilDestroyed()).subscribe((e) => {
532
+ this.events$.subscribe((e) => {
500
533
  if (e.type === 'translationLoadSuccess' && e.wasFailure) {
501
534
  this.setActiveLang(e.payload.langName);
502
535
  }
503
536
  });
537
+ this.destroyRef.onDestroy(() => {
538
+ // Complete subjects to release observers if users forget to unsubscribe manually.
539
+ // This is important in server-side rendering.
540
+ this.lang.complete();
541
+ this.events.complete();
542
+ // As a root provider, this service is destroyed with when the application is destroyed.
543
+ // Cached values retain `this`, causing circular references that block garbage collection,
544
+ // leading to memory leaks during server-side rendering.
545
+ this.cache.clear();
546
+ });
504
547
  }
505
548
  getDefaultLang() {
506
549
  return this.defaultLang;
@@ -582,7 +625,7 @@ class TranslocoService {
582
625
  console.error(`Error while trying to load "${path}"`, error);
583
626
  }
584
627
  return this.handleFailure(path, options);
585
- }), shareReplay(1));
628
+ }), shareReplay(1), takeUntilDestroyed(this.destroyRef));
586
629
  this.cache.set(path, load$);
587
630
  return load$;
588
631
  }
@@ -864,13 +907,6 @@ class TranslocoService {
864
907
  }
865
908
  this.config.scopeMapping[scope] = alias;
866
909
  }
867
- ngOnDestroy() {
868
- // Caretaker note: since this is the root provider, it'll be destroyed when the `NgModuleRef.destroy()` is run.
869
- // Cached values capture `this`, thus leading to a circular reference and preventing the `TranslocoService` from
870
- // being GC'd. This would lead to a memory leak when server-side rendering is used since the service is created
871
- // and destroyed per each HTTP request, but any service is not getting GC'd.
872
- this.cache.clear();
873
- }
874
910
  isLoadedTranslation(lang) {
875
911
  return size(this.getTranslation(lang));
876
912
  }
@@ -985,10 +1021,10 @@ class TranslocoService {
985
1021
  getEntries(key) {
986
1022
  return key instanceof Map ? key.entries() : Object.entries(key);
987
1023
  }
988
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoService, deps: [{ token: TRANSLOCO_LOADER, optional: true }, { token: TRANSLOCO_TRANSPILER }, { token: TRANSLOCO_MISSING_HANDLER }, { token: TRANSLOCO_INTERCEPTOR }, { token: TRANSLOCO_CONFIG }, { token: TRANSLOCO_FALLBACK_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
989
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoService, providedIn: 'root' });
1024
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoService, deps: [{ token: TRANSLOCO_LOADER, optional: true }, { token: TRANSLOCO_TRANSPILER }, { token: TRANSLOCO_MISSING_HANDLER }, { token: TRANSLOCO_INTERCEPTOR }, { token: TRANSLOCO_CONFIG }, { token: TRANSLOCO_FALLBACK_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
1025
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoService, providedIn: 'root' });
990
1026
  }
991
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoService, decorators: [{
1027
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoService, decorators: [{
992
1028
  type: Injectable,
993
1029
  args: [{ providedIn: 'root' }]
994
1030
  }], ctorParameters: () => [{ type: undefined, decorators: [{
@@ -1015,12 +1051,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImpor
1015
1051
 
1016
1052
  class TranslocoLoaderComponent {
1017
1053
  html;
1018
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoLoaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1019
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.0.4", type: TranslocoLoaderComponent, isStandalone: true, selector: "ng-component", inputs: { html: "html" }, ngImport: i0, template: `
1054
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoLoaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1055
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: TranslocoLoaderComponent, isStandalone: true, selector: "ng-component", inputs: { html: "html" }, ngImport: i0, template: `
1020
1056
  <div class="transloco-loader-template" [innerHTML]="html"></div>
1021
1057
  `, isInline: true });
1022
1058
  }
1023
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoLoaderComponent, decorators: [{
1059
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoLoaderComponent, decorators: [{
1024
1060
  type: Component,
1025
1061
  args: [{
1026
1062
  template: `
@@ -1057,11 +1093,13 @@ class TemplateHandler {
1057
1093
  }
1058
1094
  }
1059
1095
 
1060
- const TRANSLOCO_LANG = new InjectionToken('TRANSLOCO_LANG');
1096
+ const TRANSLOCO_LANG = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LANG' : '');
1061
1097
 
1062
- const TRANSLOCO_LOADING_TEMPLATE = new InjectionToken('TRANSLOCO_LOADING_TEMPLATE');
1098
+ const TRANSLOCO_LOADING_TEMPLATE = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode
1099
+ ? 'TRANSLOCO_LOADING_TEMPLATE'
1100
+ : '');
1063
1101
 
1064
- const TRANSLOCO_SCOPE = new InjectionToken('TRANSLOCO_SCOPE');
1102
+ const TRANSLOCO_SCOPE = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_SCOPE' : '');
1065
1103
 
1066
1104
  class LangResolver {
1067
1105
  initialized = false;
@@ -1264,10 +1302,10 @@ class TranslocoDirective {
1264
1302
  const inlineLoader = resolveInlineLoader(providerScope, resolvedScope);
1265
1303
  return this.service._loadDependencies(this.path, inlineLoader);
1266
1304
  }
1267
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1268
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.0.4", type: TranslocoDirective, isStandalone: true, selector: "[transloco]", inputs: { key: ["transloco", "key"], params: ["translocoParams", "params"], inlineScope: ["translocoScope", "inlineScope"], inlineRead: ["translocoRead", "inlineRead"], prefix: ["translocoPrefix", "prefix"], inlineLang: ["translocoLang", "inlineLang"], inlineTpl: ["translocoLoadingTpl", "inlineTpl"] }, usesOnChanges: true, ngImport: i0 });
1305
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1306
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.9", type: TranslocoDirective, isStandalone: true, selector: "[transloco]", inputs: { key: ["transloco", "key"], params: ["translocoParams", "params"], inlineScope: ["translocoScope", "inlineScope"], inlineRead: ["translocoRead", "inlineRead"], prefix: ["translocoPrefix", "prefix"], inlineLang: ["translocoLang", "inlineLang"], inlineTpl: ["translocoLoadingTpl", "inlineTpl"] }, usesOnChanges: true, ngImport: i0 });
1269
1307
  }
1270
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoDirective, decorators: [{
1308
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoDirective, decorators: [{
1271
1309
  type: Directive,
1272
1310
  args: [{
1273
1311
  selector: '[transloco]',
@@ -1361,10 +1399,10 @@ class TranslocoPipe {
1361
1399
  const inlineLoader = resolveInlineLoader(providerScope, resolvedScope);
1362
1400
  return this.service._loadDependencies(this.path, inlineLoader);
1363
1401
  }
1364
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoPipe, deps: [{ token: TranslocoService }, { token: TRANSLOCO_SCOPE, optional: true }, { token: TRANSLOCO_LANG, optional: true }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Pipe });
1365
- static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.0.4", ngImport: i0, type: TranslocoPipe, isStandalone: true, name: "transloco", pure: false });
1402
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoPipe, deps: [{ token: TranslocoService }, { token: TRANSLOCO_SCOPE, optional: true }, { token: TRANSLOCO_LANG, optional: true }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Pipe });
1403
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.2.9", ngImport: i0, type: TranslocoPipe, isStandalone: true, name: "transloco", pure: false });
1366
1404
  }
1367
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoPipe, decorators: [{
1405
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoPipe, decorators: [{
1368
1406
  type: Pipe,
1369
1407
  args: [{
1370
1408
  name: 'transloco',
@@ -1385,11 +1423,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImpor
1385
1423
 
1386
1424
  const decl = [TranslocoDirective, TranslocoPipe];
1387
1425
  class TranslocoModule {
1388
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1389
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.4", ngImport: i0, type: TranslocoModule, imports: [TranslocoDirective, TranslocoPipe], exports: [TranslocoDirective, TranslocoPipe] });
1390
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoModule });
1426
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1427
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.9", ngImport: i0, type: TranslocoModule, imports: [TranslocoDirective, TranslocoPipe], exports: [TranslocoDirective, TranslocoPipe] });
1428
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoModule });
1391
1429
  }
1392
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoModule, decorators: [{
1430
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoModule, decorators: [{
1393
1431
  type: NgModule,
1394
1432
  args: [{
1395
1433
  imports: decl,
@@ -1489,10 +1527,10 @@ class TestingLoader {
1489
1527
  getTranslation(lang) {
1490
1528
  return of(this.langs[lang]);
1491
1529
  }
1492
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TestingLoader, deps: [{ token: TRANSLOCO_TEST_LANGS }], target: i0.ɵɵFactoryTarget.Injectable });
1493
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TestingLoader });
1530
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TestingLoader, deps: [{ token: TRANSLOCO_TEST_LANGS }], target: i0.ɵɵFactoryTarget.Injectable });
1531
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TestingLoader });
1494
1532
  }
1495
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TestingLoader, decorators: [{
1533
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TestingLoader, decorators: [{
1496
1534
  type: Injectable
1497
1535
  }], ctorParameters: () => [{ type: undefined, decorators: [{
1498
1536
  type: Inject,
@@ -1538,11 +1576,11 @@ class TranslocoTestingModule {
1538
1576
  ],
1539
1577
  };
1540
1578
  }
1541
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1542
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.4", ngImport: i0, type: TranslocoTestingModule, exports: [TranslocoModule] });
1543
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoTestingModule, imports: [TranslocoModule] });
1579
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1580
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.9", ngImport: i0, type: TranslocoTestingModule, exports: [TranslocoModule] });
1581
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoTestingModule, imports: [TranslocoModule] });
1544
1582
  }
1545
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.4", ngImport: i0, type: TranslocoTestingModule, decorators: [{
1583
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: TranslocoTestingModule, decorators: [{
1546
1584
  type: NgModule,
1547
1585
  args: [{
1548
1586
  exports: [TranslocoModule],
@@ -1576,9 +1614,103 @@ function getBrowserCultureLang() {
1576
1614
  return navigator.languages?.[0] ?? navigator.language;
1577
1615
  }
1578
1616
 
1617
+ /**
1618
+ * Gets the translated value of a key as Signal
1619
+ *
1620
+ * @example
1621
+ * text = translateSignal('hello');
1622
+ * textList = translateSignal(['green', 'blue']);
1623
+ * textVar = translateSignal('hello', { variable: 'world' });
1624
+ * textSpanish = translateSignal('hello', { variable: 'world' }, 'es');
1625
+ * textTodosScope = translateSignal('hello', { variable: 'world' }, { scope: 'todos' });
1626
+ *
1627
+ * @example
1628
+ * dynamicKey = signal('hello');
1629
+ * dynamicParam = signal({ variable: 'world' });
1630
+ * text = translateSignal(this.dynamicKey, this.dynamicParam);
1631
+ *
1632
+ */
1633
+ function translateSignal(key, params, lang, injector) {
1634
+ if (!injector) {
1635
+ assertInInjectionContext(translateSignal);
1636
+ }
1637
+ injector ??= inject(Injector);
1638
+ const result = runInInjectionContext(injector, () => {
1639
+ const service = inject(TranslocoService);
1640
+ const scope = resolveScope(lang);
1641
+ return toObservable(computerKeysAndParams(key, params)).pipe(switchMap((dynamic) => service.selectTranslate(dynamic.key, dynamic.params, scope)));
1642
+ });
1643
+ return toSignal(result, { initialValue: Array.isArray(key) ? [''] : '' });
1644
+ }
1645
+ /**
1646
+ * Gets the translated object of a key as Signal
1647
+ *
1648
+ * @example
1649
+ * object = translateObjectSignal('nested.object');
1650
+ * title = object().title;
1651
+ *
1652
+ * @example
1653
+ * dynamicKey = signal('nested.object');
1654
+ * dynamicParam = signal({ variable: 'world' });
1655
+ * object = translateObjectSignal(this.dynamicKey, this.dynamicParam);
1656
+ */
1657
+ function translateObjectSignal(key, params, lang, injector) {
1658
+ if (!injector) {
1659
+ assertInInjectionContext(translateObjectSignal);
1660
+ }
1661
+ injector ??= inject(Injector);
1662
+ const result = runInInjectionContext(injector, () => {
1663
+ const service = inject(TranslocoService);
1664
+ const scope = resolveScope(lang);
1665
+ return toObservable(computerKeysAndParams(key, params)).pipe(switchMap((dynamic) => service.selectTranslateObject(dynamic.key, dynamic.params, scope)));
1666
+ });
1667
+ return toSignal(result, { initialValue: Array.isArray(key) ? [] : {} });
1668
+ }
1669
+ function computerParams(params) {
1670
+ if (isSignal(params)) {
1671
+ return computed(() => params());
1672
+ }
1673
+ return computed(() => {
1674
+ return Object.entries(params).reduce((acc, [key, value]) => {
1675
+ acc[key] = isSignal(value) ? value() : value;
1676
+ return acc;
1677
+ }, {});
1678
+ });
1679
+ }
1680
+ function computerKeys(keys) {
1681
+ if (Array.isArray(keys)) {
1682
+ return computed(() => keys.map((key) => (isSignal(key) ? key() : key)));
1683
+ }
1684
+ return computed(() => keys());
1685
+ }
1686
+ function isSignalKey(key) {
1687
+ return Array.isArray(key) ? key.some(isSignal) : isSignal(key);
1688
+ }
1689
+ function isSignalParams(params) {
1690
+ return params
1691
+ ? isSignal(params) || Object.values(params).some(isSignal)
1692
+ : false;
1693
+ }
1694
+ function computerKeysAndParams(key, params) {
1695
+ const computedKeys = isSignalKey(key)
1696
+ ? computerKeys(key)
1697
+ : computed(() => key);
1698
+ const computedParams = isSignalParams(params)
1699
+ ? computerParams(params)
1700
+ : computed(() => params);
1701
+ return computed(() => ({ key: computedKeys(), params: computedParams() }));
1702
+ }
1703
+ function resolveScope(scope) {
1704
+ if (typeof scope === 'undefined' || scope === '') {
1705
+ const translocoScope = inject(TRANSLOCO_SCOPE, { optional: true });
1706
+ return translocoScope ?? undefined;
1707
+ }
1708
+ return scope;
1709
+ }
1710
+
1579
1711
  /**
1580
1712
  * Generated bundle index. Do not edit.
1581
1713
  */
1582
1714
 
1583
- export { DefaultFallbackStrategy, DefaultInterceptor, DefaultMissingHandler, DefaultTranspiler, FunctionalTranspiler, TRANSLOCO_CONFIG, TRANSLOCO_FALLBACK_STRATEGY, TRANSLOCO_INTERCEPTOR, TRANSLOCO_LANG, TRANSLOCO_LOADER, TRANSLOCO_LOADING_TEMPLATE, TRANSLOCO_MISSING_HANDLER, TRANSLOCO_SCOPE, TRANSLOCO_TRANSPILER, TestingLoader, TranslocoDirective, TranslocoModule, TranslocoPipe, TranslocoService, TranslocoTestingModule, coerceArray, defaultConfig, flatten, getBrowserCultureLang, getBrowserLang, getFunctionArgs, getLangFromScope, getPipeValue, getScopeFromLang, getValue, hasInlineLoader, isBrowser, isDefined, isEmpty, isFunction, isNil, isNumber, isObject, isScopeObject, isString, provideTransloco, provideTranslocoConfig, provideTranslocoFallbackStrategy, provideTranslocoInterceptor, provideTranslocoLang, provideTranslocoLoader, provideTranslocoLoadingTpl, provideTranslocoMissingHandler, provideTranslocoScope, provideTranslocoTranspiler, setValue, size, toCamelCase, toNumber, translate, translateObject, translocoConfig, unflatten };
1715
+ export { DefaultFallbackStrategy, DefaultInterceptor, DefaultMissingHandler, DefaultTranspiler, FunctionalTranspiler, TRANSLOCO_CONFIG, TRANSLOCO_FALLBACK_STRATEGY, TRANSLOCO_INTERCEPTOR, TRANSLOCO_LANG, TRANSLOCO_LOADER, TRANSLOCO_LOADING_TEMPLATE, TRANSLOCO_MISSING_HANDLER, TRANSLOCO_SCOPE, TRANSLOCO_TRANSPILER, TestingLoader, TranslocoDirective, TranslocoModule, TranslocoPipe, TranslocoService, TranslocoTestingModule, coerceArray, defaultConfig, flatten, getBrowserCultureLang, getBrowserLang, getFunctionArgs, getLangFromScope, getPipeValue, getScopeFromLang, getValue, hasInlineLoader, isBrowser, isDefined, isEmpty, isFunction, isNil, isNumber, isObject, isScopeObject, isString, provideTransloco, provideTranslocoConfig, provideTranslocoFallbackStrategy, provideTranslocoInterceptor, provideTranslocoLang, provideTranslocoLoader, provideTranslocoLoadingTpl, provideTranslocoMissingHandler, provideTranslocoScope, provideTranslocoTranspiler, setValue, size, toCamelCase, toNumber, translate, translateObject, translateObjectSignal, translateSignal, translocoConfig, unflatten };
1584
1716
  //# sourceMappingURL=jsverse-transloco.mjs.map