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

Function matchLocale

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

Source from the content-addressed store, hash-verified

1225];
1226
1227function matchLocale(defaultLocale: string) {
1228 let parsed: Intl.Locale;
1229 try {
1230 parsed = new Intl.Locale(defaultLocale);
1231 } catch {
1232 return 'en-US';
1233 }
1234
1235 let locales = preferences.map(p => new Intl.Locale(p.value));
1236
1237 // Try with both language and region first, and if that fails, try again with just language
1238 let p =
1239 locales.find(
1240 locale => locale.language === parsed.language && locale.region === parsed.region
1241 ) || locales.find(locale => locale.language === parsed.language);
1242 return p?.toString() || 'en-US';
1243}
1244
1245function LocaleControl({control, value, onChange}: ControlProps) {
1246 let {locale: defaultLocale} = useLocale();

Callers 1

LocaleControlFunction · 0.70

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected