MCPcopy Create free account
hub / github.com/adobe/react-spectrum / matchLocale

Function matchLocale

packages/dev/s2-docs/src/VisualExampleClient.tsx:1210–1226  ·  view source on GitHub ↗
(defaultLocale: string)

Source from the content-addressed store, hash-verified

1208];
1209
1210function matchLocale(defaultLocale: string) {
1211 let parsed: Intl.Locale;
1212 try {
1213 parsed = new Intl.Locale(defaultLocale);
1214 } catch {
1215 return 'en-US';
1216 }
1217
1218 let locales = preferences.map(p => new Intl.Locale(p.value));
1219
1220 // Try with both language and region first, and if that fails, try again with just language
1221 let p =
1222 locales.find(
1223 locale => locale.language === parsed.language && locale.region === parsed.region
1224 ) || locales.find(locale => locale.language === parsed.language);
1225 return p?.toString() || 'en-US';
1226}
1227
1228function LocaleControl({control, value, onChange}: ControlProps) {
1229 let {locale: defaultLocale} = useLocale();

Callers 1

LocaleControlFunction · 0.70

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected