UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

37 lines (36 loc) 1.27 kB
import { warnOnce } from '../../../internal/logging'; var getHtmlElement = function () { return (typeof document !== 'undefined' ? document.querySelector('html') : null); }; function getBrowserLocale() { return new Intl.DateTimeFormat().resolvedOptions().locale; } function checkLocale(locale) { if (!locale || locale === '') { return ''; } locale = locale && locale.replace(/^([a-z]{2})_/, '$1-'); if (locale && !locale.match(/^[a-z]{2}(-[A-Z]{2})?$/)) { warnOnce('DatePicker', "Invalid locale provided: " + locale + ". Falling back to default"); locale = ''; } return locale; } export function mergeLocales(locale, fullLocale) { var isShort = locale.length === 2; if (isShort && fullLocale.indexOf(locale) === 0) { return fullLocale; } return locale; } export function normalizeLocale(locale) { var _a; locale = checkLocale(locale); var browserLocale = getBrowserLocale(); if (locale) { return mergeLocales(locale, browserLocale); } var htmlLocale = checkLocale((_a = getHtmlElement()) === null || _a === void 0 ? void 0 : _a.getAttribute('lang')); if (htmlLocale) { return mergeLocales(htmlLocale, browserLocale); } return browserLocale; }