@stemy/ngx-utils 19.9.18 → 19.9.19

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.
@@ -3998,12 +3998,12 @@ class ConfigService {
3998
3998
  }
3999
3999
  const configUrl = this.configUrl;
4000
4000
  try {
4001
- const config5 = await this.http.get(isDevMode() ? `${configUrl}5` : configUrl, { responseType: "text" }).toPromise();
4001
+ const config5 = await firstValueFrom(this.http.get(isDevMode() ? `${configUrl}5` : configUrl, { responseType: "text" }));
4002
4002
  return JSON5.parse(config5);
4003
4003
  }
4004
4004
  catch (e) {
4005
4005
  try {
4006
- const config = await this.http.get(configUrl).toPromise();
4006
+ const config = await firstValueFrom(this.http.get(configUrl));
4007
4007
  console.log(`Can't parse json5 config: ${e}`);
4008
4008
  return config;
4009
4009
  }
@@ -4012,8 +4012,14 @@ class ConfigService {
4012
4012
  }
4013
4013
  }
4014
4014
  }
4015
- prepareConfig(config) {
4016
- return Promise.resolve(config);
4015
+ async prepareConfig(config) {
4016
+ config.apiUrl = this.prepareUrl(config.apiUrl, "/");
4017
+ config.translationUrl = this.prepareUrl(config.translationUrl, "/");
4018
+ config.translationUrls = config.translationUrls || {};
4019
+ Object.entries(config.translationUrls).forEach(([key, value]) => {
4020
+ config.translationUrls[key] = this.prepareUrl(value, "/");
4021
+ });
4022
+ return config;
4017
4023
  }
4018
4024
  cloneRootElem() {
4019
4025
  if (this.rootElement instanceof HTMLElement) {
@@ -4666,22 +4672,38 @@ class LanguageService extends StaticLanguageService {
4666
4672
  if (!lang)
4667
4673
  return EMPTY_DICT;
4668
4674
  const ext = this.config.translationExt || ``;
4669
- this.translationRequests[lang] = this.translationRequests[lang] || firstValueFrom(this.client.get(`${this.config.translationUrl}${lang}${ext}`))
4670
- .then(response => {
4671
- response = response || {};
4672
- const dictionary = Object.keys(response).reduce((result, key) => {
4673
- result[key.toLocaleLowerCase()] = response[key];
4674
- return result;
4675
- }, {});
4675
+ this.translationRequests[lang] = this.translationRequests[lang] || this.getMergedDictionary(lang, ext)
4676
+ .then(dictionary => {
4676
4677
  this.translations[lang] = dictionary;
4677
4678
  this.mergeTranslations();
4678
- return dictionary;
4679
+ return this.mergedTranslations[lang];
4679
4680
  }).catch(error => {
4680
4681
  console.warn("Translation dictionary problem:", error);
4681
4682
  return EMPTY_DICT;
4682
4683
  });
4683
4684
  return this.translationRequests[lang];
4684
4685
  }
4686
+ async getMergedDictionary(lang, ext) {
4687
+ const urls = [...Object.values(this.config.translationUrls || {}), this.config.translationUrl]
4688
+ .filter(ObjectUtils.isStringWithValue)
4689
+ .map(url => `${url}${lang}${ext}`);
4690
+ const translations = await Promise.all(urls.map(async (url) => {
4691
+ try {
4692
+ return await firstValueFrom(this.client.get(url));
4693
+ }
4694
+ catch (error) {
4695
+ console.warn(`Translation dictionary problem: '${url}'`, error);
4696
+ return EMPTY_DICT;
4697
+ }
4698
+ }));
4699
+ const result = {};
4700
+ translations.forEach(dict => {
4701
+ Object.entries(dict).forEach(([key, value]) => {
4702
+ result[key.toLocaleLowerCase()] = value;
4703
+ });
4704
+ });
4705
+ return result;
4706
+ }
4685
4707
  async loadDictionary() {
4686
4708
  return this.getDictionary(this.currentLang);
4687
4709
  }