(defaultLocale: string)
| 1208 | ]; |
| 1209 | |
| 1210 | function 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 | |
| 1228 | function LocaleControl({control, value, onChange}: ControlProps) { |
| 1229 | let {locale: defaultLocale} = useLocale(); |
no test coverage detected