@equinor/eds-core-react
Version:
The React implementation of the Equinor Design System
14 lines (11 loc) • 569 B
JavaScript
import { useLocale } from 'react-aria';
const useGetLocale = locale => {
const {
locale: externalLocale
} = useLocale();
// react-aria defaults to navigator.language if no locale is provided. If these are equal, we override by using the system default locale
const defaultLocale = typeof navigator !== 'undefined' && navigator.language || 'en-US';
const fallbackLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
return locale ?? (externalLocale === defaultLocale ? undefined : externalLocale) ?? fallbackLocale;
};
export { useGetLocale };