UNPKG

@vyxos/astro-i18next

Version:

I18next integration for Astro with dynamic namespace loading.

30 lines (28 loc) 1.09 kB
// src/utils/config.ts function getConfigOptions() { if (typeof window !== "undefined" && window.__astroI18nConfig) { return window.__astroI18nConfig; } if (typeof globalThis !== "undefined" && globalThis.__astroI18nConfig) { return globalThis.__astroI18nConfig; } throw new Error( "[astro-i18next] Configuration not available. Make sure the integration is properly configured." ); } // src/utils/localization.ts function getLocalizedPathname(pathname, locale = "") { const { defaultLocale, locales } = getConfigOptions(); const localeFromPathname = pathname.split("/")[1]; let localizedPathname = pathname; if (locales.includes(localeFromPathname)) { localizedPathname = localizedPathname.replace("/" + localeFromPathname, "") || "/"; } if (locales.includes(locale) && locale !== defaultLocale) { localizedPathname = "/" + locale + localizedPathname.replace(/^\/$/, ""); } return localizedPathname; } export { getConfigOptions as getLocaleConfig, getLocalizedPathname }; //# sourceMappingURL=utils.js.map //# sourceMappingURL=utils.js.map