@jsverse/transloco 7.2.0 → 7.3.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 (121) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/esm2022/index.mjs +3 -3
  3. package/esm2022/lib/transloco-missing-handler.mjs +5 -5
  4. package/esm2022/lib/transloco.directive.mjs +6 -11
  5. package/esm2022/lib/transloco.providers.mjs +3 -3
  6. package/esm2022/lib/transloco.service.mjs +7 -10
  7. package/fesm2022/jsverse-transloco.mjs +16 -25
  8. package/fesm2022/jsverse-transloco.mjs.map +1 -1
  9. package/index.d.ts +2 -2
  10. package/lib/transloco-missing-handler.d.ts +3 -3
  11. package/lib/transloco.directive.d.ts +1 -2
  12. package/lib/transloco.service.d.ts +0 -1
  13. package/package.json +1 -1
  14. package/schematics/src/assets/i18n/en.json +1 -0
  15. package/schematics/src/collection.json +59 -0
  16. package/schematics/src/component/index.d.ts +2 -0
  17. package/schematics/src/component/index.js +21 -0
  18. package/schematics/src/component/index.js.map +1 -0
  19. package/schematics/src/join/index.d.ts +3 -0
  20. package/schematics/src/join/index.js +79 -0
  21. package/schematics/src/join/index.js.map +1 -0
  22. package/schematics/src/join/schema.d.ts +28 -0
  23. package/schematics/src/join/schema.js +3 -0
  24. package/schematics/src/join/schema.js.map +1 -0
  25. package/schematics/src/join/schema.json +43 -0
  26. package/schematics/src/keys-manager/index.d.ts +5 -0
  27. package/schematics/src/keys-manager/index.js +97 -0
  28. package/schematics/src/keys-manager/index.js.map +1 -0
  29. package/schematics/src/keys-manager/schema.d.ts +19 -0
  30. package/schematics/src/keys-manager/schema.js +3 -0
  31. package/schematics/src/keys-manager/schema.js.map +1 -0
  32. package/schematics/src/keys-manager/schema.json +33 -0
  33. package/schematics/src/migrate/index.d.ts +3 -0
  34. package/schematics/src/migrate/index.js +21 -0
  35. package/schematics/src/migrate/index.js.map +1 -0
  36. package/schematics/src/migrate/ngx-translate-migration.d.ts +3 -0
  37. package/schematics/src/migrate/ngx-translate-migration.js +169 -0
  38. package/schematics/src/migrate/ngx-translate-migration.js.map +1 -0
  39. package/schematics/src/migrate/schema.d.ts +10 -0
  40. package/schematics/src/migrate/schema.js +3 -0
  41. package/schematics/src/migrate/schema.js.map +1 -0
  42. package/schematics/src/migrate/schema.json +23 -0
  43. package/schematics/src/ng-add/files/transloco-loader/transloco-loader.__ts__ +12 -0
  44. package/schematics/src/ng-add/files/transloco-module/transloco-root.module.__ts__ +24 -0
  45. package/schematics/src/ng-add/generators/http-loader.gen.d.ts +4 -0
  46. package/schematics/src/ng-add/generators/http-loader.gen.js +15 -0
  47. package/schematics/src/ng-add/generators/http-loader.gen.js.map +1 -0
  48. package/schematics/src/ng-add/generators/root-module.gen.d.ts +9 -0
  49. package/schematics/src/ng-add/generators/root-module.gen.js +31 -0
  50. package/schematics/src/ng-add/generators/root-module.gen.js.map +1 -0
  51. package/schematics/src/ng-add/generators/translation-files.gen.d.ts +4 -0
  52. package/schematics/src/ng-add/generators/translation-files.gen.js +23 -0
  53. package/schematics/src/ng-add/generators/translation-files.gen.js.map +1 -0
  54. package/schematics/src/ng-add/index.d.ts +3 -0
  55. package/schematics/src/ng-add/index.js +103 -0
  56. package/schematics/src/ng-add/index.js.map +1 -0
  57. package/schematics/src/ng-add/schema.d.ts +42 -0
  58. package/schematics/src/ng-add/schema.js +14 -0
  59. package/schematics/src/ng-add/schema.js.map +1 -0
  60. package/schematics/src/ng-add/schema.json +53 -0
  61. package/schematics/src/ng-migrate/index.d.ts +3 -0
  62. package/schematics/src/ng-migrate/index.js +14 -0
  63. package/schematics/src/ng-migrate/index.js.map +1 -0
  64. package/schematics/src/ng-migrate/ng-migrate.d.ts +5 -0
  65. package/schematics/src/ng-migrate/ng-migrate.js +106 -0
  66. package/schematics/src/ng-migrate/ng-migrate.js.map +1 -0
  67. package/schematics/src/ng-migrate/schema.d.ts +14 -0
  68. package/schematics/src/ng-migrate/schema.js +3 -0
  69. package/schematics/src/ng-migrate/schema.js.map +1 -0
  70. package/schematics/src/ng-migrate/schema.json +27 -0
  71. package/schematics/src/schematics.consts.d.ts +4 -0
  72. package/schematics/src/schematics.consts.js +8 -0
  73. package/schematics/src/schematics.consts.js.map +1 -0
  74. package/schematics/src/scope/index.d.ts +3 -0
  75. package/schematics/src/scope/index.js +101 -0
  76. package/schematics/src/scope/index.js.map +1 -0
  77. package/schematics/src/scope/schema.d.ts +28 -0
  78. package/schematics/src/scope/schema.js +3 -0
  79. package/schematics/src/scope/schema.js.map +1 -0
  80. package/schematics/src/scope/schema.json +84 -0
  81. package/schematics/src/split/index.d.ts +3 -0
  82. package/schematics/src/split/index.js +66 -0
  83. package/schematics/src/split/index.js.map +1 -0
  84. package/schematics/src/split/schema.d.ts +20 -0
  85. package/schematics/src/split/schema.js +3 -0
  86. package/schematics/src/split/schema.js.map +1 -0
  87. package/schematics/src/split/schema.json +35 -0
  88. package/schematics/src/types.d.ts +5 -0
  89. package/schematics/src/types.js +10 -0
  90. package/schematics/src/types.js.map +1 -0
  91. package/schematics/src/upgrade/index.d.ts +3 -0
  92. package/schematics/src/upgrade/index.js +19 -0
  93. package/schematics/src/upgrade/index.js.map +1 -0
  94. package/schematics/src/upgrade/schema.d.ts +6 -0
  95. package/schematics/src/upgrade/schema.js +3 -0
  96. package/schematics/src/upgrade/schema.js.map +1 -0
  97. package/schematics/src/upgrade/schema.json +16 -0
  98. package/schematics/src/upgrade/v2.d.ts +1 -0
  99. package/schematics/src/upgrade/v2.js +89 -0
  100. package/schematics/src/upgrade/v2.js.map +1 -0
  101. package/schematics/src/utils/array.d.ts +3 -0
  102. package/schematics/src/utils/array.js +12 -0
  103. package/schematics/src/utils/array.js.map +1 -0
  104. package/schematics/src/utils/config.d.ts +2 -0
  105. package/schematics/src/utils/config.js +13 -0
  106. package/schematics/src/utils/config.js.map +1 -0
  107. package/schematics/src/utils/find-module.d.ts +23 -0
  108. package/schematics/src/utils/find-module.js +110 -0
  109. package/schematics/src/utils/find-module.js.map +1 -0
  110. package/schematics/src/utils/package.d.ts +5 -0
  111. package/schematics/src/utils/package.js +19 -0
  112. package/schematics/src/utils/package.js.map +1 -0
  113. package/schematics/src/utils/projects.d.ts +8 -0
  114. package/schematics/src/utils/projects.js +56 -0
  115. package/schematics/src/utils/projects.js.map +1 -0
  116. package/schematics/src/utils/translations.d.ts +7 -0
  117. package/schematics/src/utils/translations.js +31 -0
  118. package/schematics/src/utils/translations.js.map +1 -0
  119. package/schematics/src/utils/transloco.d.ts +24 -0
  120. package/schematics/src/utils/transloco.js +93 -0
  121. package/schematics/src/utils/transloco.js.map +1 -0
@@ -1,6 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, Injectable, Injector, Inject, Optional, Component, Input, TemplateRef, ChangeDetectorRef, ElementRef, ViewContainerRef, Renderer2, Directive, Pipe, NgModule, makeEnvironmentProviders, APP_INITIALIZER } 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';
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';
4
5
  import { unflatten as unflatten$1, flatten as flatten$1 } from 'flat';
5
6
 
6
7
  class DefaultLoader {
@@ -295,7 +296,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.9", ngImpor
295
296
  }] });
296
297
 
297
298
  const TRANSLOCO_MISSING_HANDLER = new InjectionToken('TRANSLOCO_MISSING_HANDLER');
298
- class DefaultHandler {
299
+ class DefaultMissingHandler {
299
300
  handle(key, config) {
300
301
  if (config.missingHandler.logMissingKey && !config.prodMode) {
301
302
  const msg = `Missing translation for '${key}'`;
@@ -303,10 +304,10 @@ class DefaultHandler {
303
304
  }
304
305
  return key;
305
306
  }
306
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.9", ngImport: i0, type: DefaultHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
307
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.9", ngImport: i0, type: DefaultHandler });
307
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.9", ngImport: i0, type: DefaultMissingHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
308
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.9", ngImport: i0, type: DefaultMissingHandler });
308
309
  }
309
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.9", ngImport: i0, type: DefaultHandler, decorators: [{
310
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.9", ngImport: i0, type: DefaultMissingHandler, decorators: [{
310
311
  type: Injectable
311
312
  }] });
312
313
 
@@ -456,7 +457,6 @@ class TranslocoService {
456
457
  interceptor;
457
458
  fallbackStrategy;
458
459
  langChanges$;
459
- subscription = null;
460
460
  translations = new Map();
461
461
  cache = new Map();
462
462
  firstFallbackLang;
@@ -489,7 +489,7 @@ class TranslocoService {
489
489
  /**
490
490
  * When we have a failure, we want to define the next language that succeeded as the active
491
491
  */
492
- this.subscription = this.events$.subscribe((e) => {
492
+ this.events$.pipe(takeUntilDestroyed()).subscribe((e) => {
493
493
  if (e.type === 'translationLoadSuccess' && e.wasFailure) {
494
494
  this.setActiveLang(e.payload.langName);
495
495
  }
@@ -604,7 +604,10 @@ class TranslocoService {
604
604
  return this._handleMissingKey(key, value, params);
605
605
  }
606
606
  return this.parser.transpile({
607
- value, params, translation, key
607
+ value,
608
+ params,
609
+ translation,
610
+ key,
608
611
  });
609
612
  }
610
613
  /**
@@ -854,12 +857,6 @@ class TranslocoService {
854
857
  this.config.scopeMapping[scope] = alias;
855
858
  }
856
859
  ngOnDestroy() {
857
- if (this.subscription) {
858
- this.subscription.unsubscribe();
859
- // Caretaker note: it's important to clean up references to subscriptions since they save the `next`
860
- // callback within its `destination` property, preventing classes from being GC'd.
861
- this.subscription = null;
862
- }
863
860
  // Caretaker note: since this is the root provider, it'll be destroyed when the `NgModuleRef.destroy()` is run.
864
861
  // Cached values capture `this`, thus leading to a circular reference and preventing the `TranslocoService` from
865
862
  // being GC'd. This would lead to a memory leak when server-side rendering is used since the service is created
@@ -1135,6 +1132,7 @@ class ScopeResolver {
1135
1132
  }
1136
1133
 
1137
1134
  class TranslocoDirective {
1135
+ destroyRef = inject(DestroyRef);
1138
1136
  service = inject(TranslocoService);
1139
1137
  tpl = inject(TemplateRef, {
1140
1138
  optional: true,
@@ -1148,7 +1146,6 @@ class TranslocoDirective {
1148
1146
  host = inject(ElementRef);
1149
1147
  vcr = inject(ViewContainerRef);
1150
1148
  renderer = inject(Renderer2);
1151
- subscription = null;
1152
1149
  view;
1153
1150
  memo = new Map();
1154
1151
  key;
@@ -1172,7 +1169,7 @@ class TranslocoDirective {
1172
1169
  }
1173
1170
  ngOnInit() {
1174
1171
  const listenToLangChange = shouldListenToLangChanges(this.service, this.providerLang || this.inlineLang);
1175
- this.subscription = this.service.langChanges$
1172
+ this.service.langChanges$
1176
1173
  .pipe(switchMap((activeLang) => {
1177
1174
  const lang = this.langResolver.resolve({
1178
1175
  inline: this.inlineLang,
@@ -1182,7 +1179,7 @@ class TranslocoDirective {
1182
1179
  return Array.isArray(this.providerScope)
1183
1180
  ? forkJoin(this.providerScope.map((providerScope) => this.resolveScope(lang, providerScope)))
1184
1181
  : this.resolveScope(lang, this.providerScope);
1185
- }), listenOrNotOperator(listenToLangChange))
1182
+ }), listenOrNotOperator(listenToLangChange), takeUntilDestroyed(this.destroyRef))
1186
1183
  .subscribe(() => {
1187
1184
  this.currentLang = this.langResolver.resolveLangBasedOnScope(this.path);
1188
1185
  this.strategy === 'attribute'
@@ -1244,12 +1241,6 @@ class TranslocoDirective {
1244
1241
  }
1245
1242
  ngOnDestroy() {
1246
1243
  this.memo.clear();
1247
- if (this.subscription) {
1248
- this.subscription.unsubscribe();
1249
- // Caretaker note: it's important to clean up references to subscriptions since they save the `next`
1250
- // callback within its `destination` property, preventing classes from being GC'd.
1251
- this.subscription = null;
1252
- }
1253
1244
  }
1254
1245
  detachLoader() {
1255
1246
  this.loaderTplHandler?.detachView();
@@ -1399,7 +1390,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.9", ngImpor
1399
1390
  function provideTransloco(options) {
1400
1391
  const providers = [
1401
1392
  provideTranslocoTranspiler(DefaultTranspiler),
1402
- provideTranslocoMissingHandler(DefaultHandler),
1393
+ provideTranslocoMissingHandler(DefaultMissingHandler),
1403
1394
  provideTranslocoInterceptor(DefaultInterceptor),
1404
1395
  provideTranslocoFallbackStrategy(DefaultFallbackStrategy),
1405
1396
  ];
@@ -1579,5 +1570,5 @@ function getBrowserCultureLang() {
1579
1570
  * Generated bundle index. Do not edit.
1580
1571
  */
1581
1572
 
1582
- export { DefaultFallbackStrategy, 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, isScopeArray, isScopeObject, isString, provideTransloco, provideTranslocoConfig, provideTranslocoFallbackStrategy, provideTranslocoInterceptor, provideTranslocoLang, provideTranslocoLoader, provideTranslocoLoadingTpl, provideTranslocoMissingHandler, provideTranslocoScope, provideTranslocoTranspiler, setValue, size, toCamelCase, toNumber, translate, translateObject, translocoConfig, unflatten };
1573
+ 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, isScopeArray, isScopeObject, isString, provideTransloco, provideTranslocoConfig, provideTranslocoFallbackStrategy, provideTranslocoInterceptor, provideTranslocoLang, provideTranslocoLoader, provideTranslocoLoadingTpl, provideTranslocoMissingHandler, provideTranslocoScope, provideTranslocoTranspiler, setValue, size, toCamelCase, toNumber, translate, translateObject, translocoConfig, unflatten };
1583
1574
  //# sourceMappingURL=jsverse-transloco.mjs.map