Skip to content

Commit abc4abb

Browse files
ayroblunecolas
authored andcommitted
[fix] dont throw if invalid locale
1 parent 1d4568d commit abc4abb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/react-native-web/src/modules/useLocale/isLocaleRTL.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ export function isLocaleRTL(locale: string): boolean {
6060
let isRTL = false;
6161
// $FlowFixMe
6262
if (Intl.Locale) {
63-
// $FlowFixMe
64-
const script = new Intl.Locale(locale).maximize().script;
65-
isRTL = rtlScripts.has(script);
63+
try {
64+
// $FlowFixMe
65+
const script = new Intl.Locale(locale).maximize().script;
66+
isRTL = rtlScripts.has(script);
67+
} catch {
68+
// RangeError: Incorrect locale information provided
69+
// Fallback to inferring from language
70+
const lang = locale.split('-')[0];
71+
isRTL = rtlLangs.has(lang);
72+
}
6673
} else {
6774
// Fallback to inferring from language
6875
const lang = locale.split('-')[0];

0 commit comments

Comments
 (0)