@flusys/ng-shared 5.0.4 → 5.1.1

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.
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
2
2
  import { inject, PLATFORM_ID, Injectable, DOCUMENT, REQUEST, signal, computed, ElementRef, input, effect, Directive, TemplateRef, ViewContainerRef, output, Pipe, Injector, isDevMode, NgModule, resource, model, runInInjectionContext, untracked, forwardRef, InjectionToken, Component, DestroyRef, ApplicationRef, viewChild, afterNextRender, ViewEncapsulation } from '@angular/core';
3
3
  import { isPlatformServer, isPlatformBrowser, CommonModule, NgOptimizedImage, NgComponentOutlet, DatePipe, DOCUMENT as DOCUMENT$1 } from '@angular/common';
4
4
  import { HttpClient, HttpContextToken, HttpHeaders, HttpParams } from '@angular/common/http';
5
- import { APP_CONFIG, getServiceUrl, LOCALIZATION_STATE_SERVICE, LOCALIZATION_API_SERVICE, FALLBACK_MESSAGES_REGISTRY } from '@flusys/ng-core';
5
+ import { APP_CONFIG, getServiceUrl, LOCALIZATION_STATE_SERVICE, FALLBACK_MESSAGES_REGISTRY, LOCALIZATION_API_SERVICE } from '@flusys/ng-core';
6
6
  import { of, catchError as catchError$1, throwError, firstValueFrom, map as map$1, from } from 'rxjs';
7
7
  import { map, tap, catchError } from 'rxjs/operators';
8
8
  import * as i1$1 from '@angular/forms';
@@ -715,26 +715,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.5", ngImpor
715
715
  }] });
716
716
 
717
717
  class TranslateService {
718
- localizationState = inject(LOCALIZATION_STATE_SERVICE);
718
+ localizationState = inject(LOCALIZATION_STATE_SERVICE, {
719
+ optional: true,
720
+ });
721
+ registry = inject(FALLBACK_MESSAGES_REGISTRY, {
722
+ optional: false,
723
+ });
719
724
  translate(key, params) {
725
+ if (this.localizationState === null) {
726
+ const value = this.registry[key];
727
+ return this.interpolate(value, params);
728
+ }
720
729
  const translations = this.localizationState.translations();
721
- const value = translations[key];
730
+ let value = translations[key];
722
731
  if (!value) {
723
- return this.getFromFallback(key, params);
732
+ const fallbacks = this.localizationState.fallbackMessages();
733
+ value = fallbacks[key] ?? key;
724
734
  }
725
735
  return this.interpolate(value, params);
726
736
  }
727
737
  translateSignal(key, params) {
728
738
  return computed(() => {
729
- this.localizationState.currentLanguage();
730
739
  return this.translate(key, params);
731
740
  });
732
741
  }
733
- getFromFallback(key, params) {
734
- const fallbacks = this.localizationState.fallbackMessages();
735
- const value = fallbacks[key] ?? key;
736
- return this.interpolate(value, params);
737
- }
738
742
  interpolate(template, params) {
739
743
  if (!params || !template)
740
744
  return template;
@@ -1206,11 +1210,7 @@ function resolveTranslationModule(config) {
1206
1210
  // Register fallback messages
1207
1211
  if (fallbackMessages) {
1208
1212
  if (locServices) {
1209
- modules.forEach((module) => {
1210
- if (!locServices.stateService.hasModuleFallbacks(module)) {
1211
- locServices.stateService.registerModuleFallbacks(module, fallbackMessages);
1212
- }
1213
- });
1213
+ locServices.stateService.updateFallbackMessages(fallbackMessages);
1214
1214
  }
1215
1215
  else {
1216
1216
  const registry = injector.get(FALLBACK_MESSAGES_REGISTRY, null);