@vyxos/astro-i18next
Version: 
I18next integration for Astro with dynamic namespace loading.
46 lines (42 loc) • 2.21 kB
TypeScript
import { a as IntegrationOptionsInternal, I as IntegrationOptions } from './integration-BunY9Y4i.js';
import 'i18next';
/**
 * Retrieves the current configuration for the astro-i18next integration.
 *
 * This function provides access to the merged configuration (internal + i18next options)
 * in both SSG (Static Site Generation) and SPA (Single Page Application) modes.
 * The configuration is automatically injected during the build process and stored globally for runtime access.
 *
 * @returns The merged configuration object containing both internal options and i18next options
 *
 * @throws {Error} Throws an error if the configuration is not available, which typically
 *   indicates that the astro-i18next integration is not properly configured.
 *
 * @since 0.1.5
 */
declare function getConfig(): IntegrationOptionsInternal & IntegrationOptions["i18NextOptions"];
/**
 * Generates a localized URL pathname based on a given path and target locale.
 *
 * This function ensures that the generated pathname correctly reflects the desired locale
 * according to the rules defined in the configuration. It first strips any existing locale
 * from the input pathname to get a base path. Then, it prepends the target locale to the
 * base path, but only if the target locale is not the default locale.
 *
 * @param {string} [pathname] - The original pathname to be localized. This can be a path
 * that already contains a locale prefix (e.g., "/en/about") or a path without one
 * (e.g., "/about"). Defaults to an empty string.
 *
 * @param {string} [locale] - The target locale code for the new pathname (e.g., "fr").
 * If this locale is the default locale, it will not be added to the path.
 * If not provided, uses the current locale from i18next.
 *
 * @returns {string} The fully resolved, localized pathname. For example:
 * - `getLocalizedPathname("/fr/about", "de")` returns `"/de/about"`
 * - `getLocalizedPathname("/about", "fr")` returns `"/fr/about"`
 * - `getLocalizedPathname("/fr/about", "en")` returns `"/about"` (if "en" is default)
 *
 * @since 0.1.5
 */
declare function getLocalizedPathname(pathname: string, locale?: string): string;
export { getConfig, getLocalizedPathname };