@vyxos/astro-i18next
Version:
I18next integration for Astro with dynamic namespace loading.
48 lines (44 loc) • 2.28 kB
TypeScript
import { I as IntegrationOptions } from './types-BHBGla7c.js';
/**
* Retrieves the current locale configuration for the astro-i18next integration.
*
* This function provides access to the locale configuration 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 {LocaleConfig} The locale configuration object containing:
* - `locales`: Array of all supported locale codes (e.g., ['en', 'fr', 'es'])
* - `defaultLocale`: The default locale code (e.g., 'en')
* - `prefixDefaultLocale`: Whether to include the default locale in URLs
*
* @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 getConfigOptions(): IntegrationOptions;
/**
* 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.
* Defaults to an empty string.
*
* @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 { getConfigOptions as getLocaleConfig, getLocalizedPathname };