(defaultLocale: string)
| 1225 | ]; |
| 1226 | |
| 1227 | function 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 | |
| 1245 | function LocaleControl({control, value, onChange}: ControlProps) { |
| 1246 | let {locale: defaultLocale} = useLocale(); |
no test coverage detected