2023-05-20 09:14:35 +03:00
|
|
|
import { match } from '@formatjs/intl-localematcher';
|
2023-06-11 18:28:12 +03:00
|
|
|
import mem from 'mem';
|
2023-05-20 09:14:35 +03:00
|
|
|
|
2023-06-11 18:28:12 +03:00
|
|
|
function _localeMatch(...args) {
|
2023-05-20 09:14:35 +03:00
|
|
|
// Wrap in try/catch because localeMatcher throws on invalid locales
|
|
|
|
try {
|
|
|
|
return match(...args);
|
|
|
|
} catch (e) {
|
2023-08-14 13:03:05 +03:00
|
|
|
const defaultLocale = args[2];
|
|
|
|
return defaultLocale || false;
|
2023-05-20 09:14:35 +03:00
|
|
|
}
|
|
|
|
}
|
2023-06-11 18:28:12 +03:00
|
|
|
const localeMatch = mem(_localeMatch, {
|
|
|
|
cacheKey: (args) => args.join(),
|
|
|
|
});
|
2023-05-20 09:14:35 +03:00
|
|
|
|
|
|
|
export default localeMatch;
|