@eui/core 19.3.7-snapshot-1760686168172 → 19.3.7-snapshot-1760859222927
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/docs/properties.html
CHANGED
package/fesm2022/eui-core.mjs
CHANGED
|
@@ -4752,6 +4752,13 @@ class LocaleService extends EuiService {
|
|
|
4752
4752
|
init(state) {
|
|
4753
4753
|
super.initEuiService();
|
|
4754
4754
|
state = state || { id: this.currentLocale };
|
|
4755
|
+
if (state?.id && !this.isValidLocale(state.id)) {
|
|
4756
|
+
const message = `Locale '${state.id}' is not a valid locale string. Please provide a valid locale.`;
|
|
4757
|
+
if (this.log) {
|
|
4758
|
+
this.logger.error(message);
|
|
4759
|
+
}
|
|
4760
|
+
return of({ success: false, error: new Error(message) });
|
|
4761
|
+
}
|
|
4755
4762
|
// bind language changes to locale changes
|
|
4756
4763
|
if (this.config?.bindWithTranslate) {
|
|
4757
4764
|
this.bindTranslateServiceLangChangeToState();
|
|
@@ -4841,6 +4848,27 @@ class LocaleService extends EuiService {
|
|
|
4841
4848
|
});
|
|
4842
4849
|
}
|
|
4843
4850
|
}
|
|
4851
|
+
/**
|
|
4852
|
+
* Checks if a given locale string is valid according to the Intl.Locale API. (based on BCP 47)
|
|
4853
|
+
* A valid locale string can be used to create a new Intl.Locale object without throwing an error.
|
|
4854
|
+
*
|
|
4855
|
+
* @param localeString - The locale string to be validated.
|
|
4856
|
+
* @returns {boolean} - Returns true if the locale string is valid, false otherwise.
|
|
4857
|
+
*/
|
|
4858
|
+
isValidLocale(localeString) {
|
|
4859
|
+
try {
|
|
4860
|
+
// Normalize: replace underscores with hyphens (support for Angular locale ids)
|
|
4861
|
+
// e.g., 'en_US' -> 'en-US'
|
|
4862
|
+
// Note: Intl.Locale only accepts hyphens as separators
|
|
4863
|
+
// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
|
|
4864
|
+
const normalizedString = localeString.replace(/_/g, '-');
|
|
4865
|
+
new Intl.Locale(normalizedString);
|
|
4866
|
+
return true;
|
|
4867
|
+
}
|
|
4868
|
+
catch (error) {
|
|
4869
|
+
return false;
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4844
4872
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LocaleService, deps: [{ token: StoreService }, { token: GLOBAL_CONFIG_TOKEN }, { token: LOCALE_ID }, { token: LOCALE_ID_MAPPER, optional: true }, { token: I18nService, optional: true }, { token: LogService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
4845
4873
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: LocaleService, providedIn: 'root' }); }
|
|
4846
4874
|
}
|