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

Function matchLocale

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

Source from the content-addressed store, hash-verified

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

Callers 1

LocaleControlFunction · 0.70

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected