@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
21 lines • 749 B
JavaScript
const dnCache = /* @__PURE__ */ new Map();
const getLocaleName = (displayLocale, targetLocale = displayLocale) => {
if (typeof Intl?.DisplayNames !== "function") {
if (process.env.NODE_ENV === "development") {
console.warn(
`Intl.DisplayNames is not supported; falling back to raw locale (${displayLocale}). Consider adding a polyfill as https://formatjs.github.io/docs/polyfills/intl-displaynames/`
);
}
return displayLocale;
}
let dn = dnCache.get(targetLocale);
if (!dn) {
dn = new Intl.DisplayNames([targetLocale], { type: "language" });
dnCache.set(targetLocale, dn);
}
return dn.of(displayLocale) ?? "Unknown locale";
};
export {
getLocaleName
};
//# sourceMappingURL=getLocaleName.mjs.map