Skip to content

Commit 5bc34d4

Browse files
authored
fix: fallback to en-US when locale resolution fails (#8589)
Co-authored-by: 印南雄悟 <>
1 parent a6e01d3 commit 5bc34d4

File tree

1 file changed

+8
-1
lines changed
  • packages/@react-stately/datepicker/src

1 file changed

+8
-1
lines changed

packages/@react-stately/datepicker/src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ function getLocale() {
2525
// Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
2626
// validation messages, which to not respect our provider's language.
2727
// @ts-ignore
28-
return (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) || 'en-US';
28+
let locale = typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
29+
30+
try {
31+
Intl.DateTimeFormat.supportedLocalesOf([locale]);
32+
} catch {
33+
locale = 'en-US';
34+
}
35+
return locale;
2936
}
3037

3138
export function getValidationResult(

0 commit comments

Comments
 (0)