mn-angular-lib 0.0.46 → 0.0.48
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.
|
@@ -631,6 +631,17 @@ class MnLanguageService {
|
|
|
631
631
|
t(key, params) {
|
|
632
632
|
return this.translate(key, params);
|
|
633
633
|
}
|
|
634
|
+
/**
|
|
635
|
+
* Resolve the effective default locale from a domain-to-locale map.
|
|
636
|
+
* Matches `window.location.hostname` against the map keys.
|
|
637
|
+
* Returns the mapped locale, or the provided fallback if no match is found.
|
|
638
|
+
*/
|
|
639
|
+
resolveLocaleForDomain(domainLocaleMap, fallback) {
|
|
640
|
+
if (!domainLocaleMap || typeof window === 'undefined')
|
|
641
|
+
return fallback;
|
|
642
|
+
const hostname = window.location.hostname;
|
|
643
|
+
return domainLocaleMap[hostname] ?? fallback;
|
|
644
|
+
}
|
|
634
645
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnLanguageService, deps: [{ token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
635
646
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnLanguageService, providedIn: 'root' });
|
|
636
647
|
}
|
|
@@ -695,9 +706,10 @@ class MnConfigService {
|
|
|
695
706
|
if (isPlainObject(langCfg) && typeof langCfg['urlPattern'] === 'string') {
|
|
696
707
|
const lc = langCfg;
|
|
697
708
|
this.lang.configure(lc.urlPattern);
|
|
698
|
-
const
|
|
709
|
+
const effectiveLocale = this.lang.resolveLocaleForDomain(lc.domainLocaleMap, lc.defaultLocale);
|
|
710
|
+
const localesToLoad = lc.preload ?? [effectiveLocale];
|
|
699
711
|
await Promise.all(localesToLoad.map(l => this.lang.loadLocale(l)));
|
|
700
|
-
await this.lang.setLocale(
|
|
712
|
+
await this.lang.setLocale(effectiveLocale);
|
|
701
713
|
}
|
|
702
714
|
}
|
|
703
715
|
/**
|
|
@@ -755,6 +767,17 @@ class MnConfigService {
|
|
|
755
767
|
if (isTranslatable(value)) {
|
|
756
768
|
out[key] = this.lang.translate(value.$translate, value.params);
|
|
757
769
|
}
|
|
770
|
+
else if (Array.isArray(value)) {
|
|
771
|
+
out[key] = value.map(item => {
|
|
772
|
+
if (isTranslatable(item)) {
|
|
773
|
+
return this.lang.translate(item.$translate, item.params);
|
|
774
|
+
}
|
|
775
|
+
else if (isPlainObject(item)) {
|
|
776
|
+
return this.resolveTranslatables(item);
|
|
777
|
+
}
|
|
778
|
+
return item;
|
|
779
|
+
});
|
|
780
|
+
}
|
|
758
781
|
else if (isPlainObject(value)) {
|
|
759
782
|
out[key] = this.resolveTranslatables(value);
|
|
760
783
|
}
|
|
@@ -4692,9 +4715,10 @@ function provideMnLanguage(config) {
|
|
|
4692
4715
|
multi: true,
|
|
4693
4716
|
useFactory: (svc) => async () => {
|
|
4694
4717
|
svc.configure(config.urlPattern);
|
|
4695
|
-
const
|
|
4718
|
+
const effectiveLocale = svc.resolveLocaleForDomain(config.domainLocaleMap, config.defaultLocale);
|
|
4719
|
+
const localesToLoad = config.preload ?? [effectiveLocale];
|
|
4696
4720
|
await Promise.all(localesToLoad.map(l => svc.loadLocale(l)));
|
|
4697
|
-
await svc.setLocale(
|
|
4721
|
+
await svc.setLocale(effectiveLocale);
|
|
4698
4722
|
},
|
|
4699
4723
|
deps: [MnLanguageService],
|
|
4700
4724
|
},
|