monkey-front-core 0.0.207 → 0.0.210

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.
@@ -2731,36 +2731,54 @@ class MonkeyEcxi18nConfigService extends MonkeyEcxCommonsService {
2731
2731
  this.translateService.setDefaultLang('pt-BR');
2732
2732
  this.translateService.use('pt-BR');
2733
2733
  }
2734
- apply(params, environment, change = false) {
2734
+ async apply(params, environment, change = false) {
2735
2735
  const { monkeyecxService, monkeyecxCookieStorageService, monkeyecxErrorConfigService } = this;
2736
2736
  let { i18n } = params;
2737
- const externali18n = params?.externali18n?.[`${i18n?.lang || 'pt-BR'}`];
2737
+ const currentExternali18n = params?.externali18n?.[`${i18n?.lang || 'pt-BR'}`];
2738
2738
  const cookie = monkeyecxCookieStorageService.getCookie('monkey-app-locale');
2739
2739
  if (cookie && !change) {
2740
2740
  i18n = JSON.parse(atob(cookie));
2741
2741
  }
2742
2742
  else {
2743
2743
  monkeyecxCookieStorageService.setCookie('monkey-app-locale', btoa(JSON.stringify(i18n)), environment);
2744
- if (!cookie)
2745
- change = true;
2746
2744
  }
2747
- monkeyecxService?.get(`${environment.localAssets}/i18n/${i18n?.lang}.json`)?.subscribe((config) => {
2748
- const { lang } = config;
2749
- let { data } = config;
2750
- if (externali18n) {
2745
+ try {
2746
+ const externali18nPaths = params?.i18n?.paths || [];
2747
+ const services = externali18nPaths?.map((url) => {
2748
+ return monkeyecxService?.get(`${url}/${i18n?.lang}.json`).pipe(take(1)).toPromise();
2749
+ });
2750
+ if (!services?.length)
2751
+ return;
2752
+ const externali18nData = await Promise.all(services);
2753
+ externali18nData?.forEach((config) => {
2754
+ const { lang } = config;
2755
+ const { data } = config;
2756
+ this.translateService.setTranslation('pt-BR', data, true);
2757
+ this.translateService.setTranslation(lang, data, true);
2758
+ });
2759
+ }
2760
+ catch (err) {
2761
+ // not to do
2762
+ }
2763
+ try {
2764
+ const currenti18n = await monkeyecxService?.get(`${environment.localAssets}/i18n/${i18n?.lang}.json`).pipe(take(1)).toPromise();
2765
+ const { lang } = currenti18n;
2766
+ let { data } = currenti18n;
2767
+ if (currentExternali18n) {
2751
2768
  data = {
2752
2769
  ...data,
2753
- EXTERNAL: externali18n
2770
+ EXTERNAL: currentExternali18n
2754
2771
  };
2755
2772
  }
2756
2773
  this.translateService.setTranslation('pt-BR', data, true);
2757
2774
  this.translateService.setTranslation(lang, data, true);
2758
2775
  this.translateService.use(lang);
2759
- }, (err) => {
2776
+ }
2777
+ catch (err) {
2760
2778
  console.error(`i18n ${i18n?.lang} not found!`);
2761
2779
  monkeyecxErrorConfigService.apply('i18n');
2762
2780
  throwError(err);
2763
- });
2781
+ }
2764
2782
  }
2765
2783
  }
2766
2784
  MonkeyEcxi18nConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxi18nConfigService, deps: [{ token: MonkeyEcxService }, { token: i1$1.TranslateService }, { token: MonkeyEcxCookieStorageService }, { token: MonkeyEcxErrorConfigService }], target: i0.ɵɵFactoryTarget.Injectable });