@eui/core 21.0.0-alpha.31 → 21.0.0-alpha.32
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.
- package/CHANGELOG.md +66 -0
- package/docs/changelog.html +142 -0
- package/docs/js/search/search_index.js +2 -2
- package/docs/properties.html +1 -1
- package/fesm2022/eui-core.mjs +28 -0
- package/fesm2022/eui-core.mjs.map +1 -1
- package/index.d.ts +8 -0
- package/index.d.ts.map +1 -1
- package/package.json +2 -2
package/docs/properties.html
CHANGED
package/fesm2022/eui-core.mjs
CHANGED
|
@@ -4680,6 +4680,13 @@ class LocaleService extends EuiService {
|
|
|
4680
4680
|
init(state) {
|
|
4681
4681
|
super.initEuiService();
|
|
4682
4682
|
state = state || { id: this.currentLocale };
|
|
4683
|
+
if (state?.id && !this.isValidLocale(state.id)) {
|
|
4684
|
+
const message = `Locale '${state.id}' is not a valid locale string. Please provide a valid locale.`;
|
|
4685
|
+
if (this.log) {
|
|
4686
|
+
this.logger.error(message);
|
|
4687
|
+
}
|
|
4688
|
+
return of({ success: false, error: new Error(message) });
|
|
4689
|
+
}
|
|
4683
4690
|
// bind language changes to locale changes
|
|
4684
4691
|
if (this.config?.bindWithTranslate) {
|
|
4685
4692
|
this.bindTranslateServiceLangChangeToState();
|
|
@@ -4769,6 +4776,27 @@ class LocaleService extends EuiService {
|
|
|
4769
4776
|
});
|
|
4770
4777
|
}
|
|
4771
4778
|
}
|
|
4779
|
+
/**
|
|
4780
|
+
* Checks if a given locale string is valid according to the Intl.Locale API. (based on BCP 47)
|
|
4781
|
+
* A valid locale string can be used to create a new Intl.Locale object without throwing an error.
|
|
4782
|
+
*
|
|
4783
|
+
* @param localeString - The locale string to be validated.
|
|
4784
|
+
* @returns {boolean} - Returns true if the locale string is valid, false otherwise.
|
|
4785
|
+
*/
|
|
4786
|
+
isValidLocale(localeString) {
|
|
4787
|
+
try {
|
|
4788
|
+
// Normalize: replace underscores with hyphens (support for Angular locale ids)
|
|
4789
|
+
// e.g., 'en_US' -> 'en-US'
|
|
4790
|
+
// Note: Intl.Locale only accepts hyphens as separators
|
|
4791
|
+
// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
|
|
4792
|
+
const normalizedString = localeString.replace(/_/g, '-');
|
|
4793
|
+
new Intl.Locale(normalizedString);
|
|
4794
|
+
return true;
|
|
4795
|
+
}
|
|
4796
|
+
catch (error) {
|
|
4797
|
+
return false;
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4772
4800
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0-next.5", ngImport: i0, type: LocaleService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
4773
4801
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0-next.5", ngImport: i0, type: LocaleService, providedIn: 'root' }); }
|
|
4774
4802
|
}
|