UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

28 lines (26 loc) 1.29 kB
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs'); let __intlayer_config_built = require("@intlayer/config/built"); __intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built); //#region src/localization/localeResolver.ts /** * Resolves the most specific locale from a user-provided list, * or falls back to the default locale if no match is found. */ const localeResolver = (selectedLocale, locales = __intlayer_config_built.default?.internationalization?.locales, defaultLocale = __intlayer_config_built.default?.internationalization?.defaultLocale) => { const requestedLocales = [selectedLocale].flat(); const normalize = (locale) => locale.trim().toLowerCase(); try { for (const requested of requestedLocales) { const normalizedRequested = normalize(requested); const exactMatch = locales.find((loc) => normalize(loc) === normalizedRequested); if (exactMatch) return exactMatch; const [requestedLang] = normalizedRequested.split("-"); const partialMatch = locales.find((loc) => normalize(loc).split("-")[0] === requestedLang); if (partialMatch) return partialMatch; } } catch (_error) {} return defaultLocale; }; //#endregion exports.localeResolver = localeResolver; //# sourceMappingURL=localeResolver.cjs.map