Skip to content

Commit

Permalink
[fix] dont throw if invalid locale
Browse files Browse the repository at this point in the history
  • Loading branch information
ayroblu authored and necolas committed Oct 16, 2024
1 parent 1d4568d commit abc4abb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/react-native-web/src/modules/useLocale/isLocaleRTL.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ export function isLocaleRTL(locale: string): boolean {
let isRTL = false;
// $FlowFixMe
if (Intl.Locale) {
// $FlowFixMe
const script = new Intl.Locale(locale).maximize().script;
isRTL = rtlScripts.has(script);
try {
// $FlowFixMe
const script = new Intl.Locale(locale).maximize().script;
isRTL = rtlScripts.has(script);
} catch {
// RangeError: Incorrect locale information provided
// Fallback to inferring from language
const lang = locale.split('-')[0];
isRTL = rtlLangs.has(lang);
}
} else {
// Fallback to inferring from language
const lang = locale.split('-')[0];
Expand Down

0 comments on commit abc4abb

Please sign in to comment.