@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
61 lines (60 loc) • 1.79 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { defaultLocale, normalizeLocale, supportedLocales } from "@arcgis/toolkit/intl";
import { d as dateFromISO } from "./date.js";
import { g as getAssetPath } from "./runtime.js";
const translationCache = {};
const requestCache = {};
const extraNlsLocales = [
"de-AT",
"de-CH",
"en-AU",
"en-CA",
"en-GB",
"es-MX",
"fr-CA",
"fr-CH",
"hi",
"it-CH",
"mk",
"pt"
];
[...supportedLocales, ...extraNlsLocales];
function normalizeNlsLocale(locale) {
if (!locale) {
return defaultLocale;
}
const localeParts = locale.split("-");
locale = `${localeParts[0].toLowerCase()}${localeParts.length >= 2 ? `-${localeParts[1].toUpperCase()}` : ""}`;
if (extraNlsLocales.includes(locale)) {
return locale;
}
return normalizeLocale(locale);
}
async function getLocaleData(locale) {
locale = normalizeNlsLocale(locale);
if (translationCache[locale]) {
return translationCache[locale];
}
if (!requestCache[locale]) {
requestCache[locale] = fetch(getAssetPath(`./assets/date-picker/nls/${locale}.json`)).then((resp) => resp.json()).catch(() => {
console.error(`Native Language Support data for "${locale}" not found or invalid, falling back to english`);
return getLocaleData(defaultLocale);
});
}
return translationCache[locale] = await requestCache[locale];
}
function applyLocaleOverride(locale) {
const localeOverrideMap = {
"ar-SA": "ar"
// see https://github.com/Esri/calcite-design-system/issues/11399
};
return localeOverrideMap[locale] || locale;
}
function getValueAsDateRange(value) {
return value.map((v, index) => dateFromISO(v, index === 1));
}
export {
applyLocaleOverride as a,
getLocaleData as b,
getValueAsDateRange as g
};