mn-angular-lib 0.0.47 → 0.0.49

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, Optional, Inject, inject, Input, ChangeDetectionStrategy, Component, HostBinding, Self, DestroyRef, APP_INITIALIZER, ElementRef, HostListener, forwardRef, Directive, EventEmitter, TemplateRef, Output, ViewChildren, ViewContainerRef, ViewChild, ApplicationRef, EnvironmentInjector, createComponent, SkipSelf, Attribute, Pipe } from '@angular/core';
2
+ import { InjectionToken, Injectable, Optional, Inject, inject, Input, ChangeDetectionStrategy, Component, HostBinding, DestroyRef, Self, APP_INITIALIZER, ElementRef, HostListener, forwardRef, Directive, EventEmitter, TemplateRef, Output, ViewChildren, ViewContainerRef, ViewChild, ApplicationRef, EnvironmentInjector, createComponent, SkipSelf, Attribute, Pipe } from '@angular/core';
3
3
  export { TemplateRef, Type } from '@angular/core';
4
4
  import { BehaviorSubject, firstValueFrom, skip, Subject, debounceTime, map, catchError, of } from 'rxjs';
5
5
  import * as i1 from '@angular/common';
@@ -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 localesToLoad = lc.preload ?? [lc.defaultLocale];
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(lc.defaultLocale);
712
+ await this.lang.setLocale(effectiveLocale);
701
713
  }
702
714
  }
703
715
  /**
@@ -858,6 +870,8 @@ class MnInputField {
858
870
  configService = inject(MnConfigService);
859
871
  sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
860
872
  explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
873
+ lang = inject(MnLanguageService);
874
+ destroyRef = inject(DestroyRef);
861
875
  /** Current raw string value of the input element */
862
876
  value = null;
863
877
  /** Whether the input is disabled */
@@ -892,6 +906,10 @@ class MnInputField {
892
906
  }
893
907
  ngOnInit() {
894
908
  this.resolveConfig();
909
+ const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
910
+ this.resolveConfig();
911
+ });
912
+ this.destroyRef.onDestroy(() => sub.unsubscribe());
895
913
  }
896
914
  resolveConfig() {
897
915
  const instanceId = this.explicitInstanceId || `mn-input-${this.props.id}`;
@@ -1360,6 +1378,8 @@ class MnTextarea {
1360
1378
  configService = inject(MnConfigService);
1361
1379
  sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
1362
1380
  explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
1381
+ lang = inject(MnLanguageService);
1382
+ destroyRef = inject(DestroyRef);
1363
1383
  /** Current raw string value of the textarea element */
1364
1384
  value = null;
1365
1385
  /** Whether the textarea is disabled */
@@ -1391,6 +1411,10 @@ class MnTextarea {
1391
1411
  }
1392
1412
  ngOnInit() {
1393
1413
  this.resolveConfig();
1414
+ const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
1415
+ this.resolveConfig();
1416
+ });
1417
+ this.destroyRef.onDestroy(() => sub.unsubscribe());
1394
1418
  }
1395
1419
  resolveConfig() {
1396
1420
  const instanceId = this.explicitInstanceId || `mn-textarea-${this.props.id}`;
@@ -1595,6 +1619,8 @@ class MnCheckbox {
1595
1619
  configService = inject(MnConfigService);
1596
1620
  sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
1597
1621
  explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
1622
+ lang = inject(MnLanguageService);
1623
+ destroyRef = inject(DestroyRef);
1598
1624
  value = false;
1599
1625
  isDisabled = false;
1600
1626
  onChange = () => { };
@@ -1609,6 +1635,10 @@ class MnCheckbox {
1609
1635
  }
1610
1636
  ngOnInit() {
1611
1637
  this.resolveConfig();
1638
+ const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
1639
+ this.resolveConfig();
1640
+ });
1641
+ this.destroyRef.onDestroy(() => sub.unsubscribe());
1612
1642
  }
1613
1643
  resolveConfig() {
1614
1644
  const instanceId = this.explicitInstanceId || `mn-checkbox-${this.props.id}`;
@@ -1754,6 +1784,8 @@ class MnDatetime {
1754
1784
  configService = inject(MnConfigService);
1755
1785
  sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
1756
1786
  explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
1787
+ lang = inject(MnLanguageService);
1788
+ destroyRef = inject(DestroyRef);
1757
1789
  value = null;
1758
1790
  isDisabled = false;
1759
1791
  onChange = () => { };
@@ -1770,6 +1802,10 @@ class MnDatetime {
1770
1802
  }
1771
1803
  ngOnInit() {
1772
1804
  this.resolveConfig();
1805
+ const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
1806
+ this.resolveConfig();
1807
+ });
1808
+ this.destroyRef.onDestroy(() => sub.unsubscribe());
1773
1809
  }
1774
1810
  resolveConfig() {
1775
1811
  const instanceId = this.explicitInstanceId || `mn-datetime-${this.props.id}`;
@@ -1924,6 +1960,8 @@ class MnMultiSelect {
1924
1960
  sectionPath = inject(MN_SECTION_PATH, { optional: true }) ?? [];
1925
1961
  explicitInstanceId = inject(MN_INSTANCE_ID, { optional: true });
1926
1962
  elRef = inject(ElementRef);
1963
+ lang = inject(MnLanguageService);
1964
+ destroyRef = inject(DestroyRef);
1927
1965
  /** Currently selected values */
1928
1966
  selectedValues = [];
1929
1967
  isOpen = false;
@@ -1941,6 +1979,10 @@ class MnMultiSelect {
1941
1979
  }
1942
1980
  ngOnInit() {
1943
1981
  this.resolveConfig();
1982
+ const sub = this.lang.locale$.pipe(skip(1)).subscribe(() => {
1983
+ this.resolveConfig();
1984
+ });
1985
+ this.destroyRef.onDestroy(() => sub.unsubscribe());
1944
1986
  }
1945
1987
  resolveConfig() {
1946
1988
  const instanceId = this.explicitInstanceId || `mn-multi-select-${this.props.id}`;
@@ -4703,9 +4745,10 @@ function provideMnLanguage(config) {
4703
4745
  multi: true,
4704
4746
  useFactory: (svc) => async () => {
4705
4747
  svc.configure(config.urlPattern);
4706
- const localesToLoad = config.preload ?? [config.defaultLocale];
4748
+ const effectiveLocale = svc.resolveLocaleForDomain(config.domainLocaleMap, config.defaultLocale);
4749
+ const localesToLoad = config.preload ?? [effectiveLocale];
4707
4750
  await Promise.all(localesToLoad.map(l => svc.loadLocale(l)));
4708
- await svc.setLocale(config.defaultLocale);
4751
+ await svc.setLocale(effectiveLocale);
4709
4752
  },
4710
4753
  deps: [MnLanguageService],
4711
4754
  },