Skip to content

Types

All types are exported from the package’s main entry point:

import type { LocaleConfig, I18nConfig, SlugMap } from '@otrodigital/astro-i18n-next';

LocaleConfig

Base configuration for locale settings.

interface LocaleConfig {
defaultLocale: string;
locales: string[];
localeLabels: Record<string, string>;
localeHtmlLang: Record<string, string>;
}
FieldDescription
defaultLocaleDefault locale code (e.g., 'en')
localesAll supported locale codes
localeLabelsHuman-readable names (e.g., { en: 'English' })
localeHtmlLangHTML lang values (e.g., { en: 'en' })

SlugMap

Maps canonical slugs to locale-specific slugs.

type SlugMap = Record<string, Record<string, string>>;

Example:

const slugMap: SlugMap = {
'about': { en: 'about', es: 'sobre' },
'model-165': { en: 'model-165', es: 'modelo-165' },
};

PageEntry

Metadata for a discovered page.

interface PageEntry {
entrypoint: string;
slugs: Record<string, string>;
}
FieldDescription
entrypointAstro component path (e.g., 'src/pages/about.astro')
slugsLocale-specific URL slugs for this page

I18nextOptions

Configuration for i18next plugins and custom init options.

interface I18nextOptions {
plugins?: any[];
options?: Record<string, unknown>;
}
FieldDescription
pluginsi18next plugins (e.g., [ICU]) — not serializable
optionsExtra i18next.init() options — serializable

I18nConfig

Full configuration for createI18n(). Extends LocaleConfig.

interface I18nConfig extends LocaleConfig {
translations: Record<string, Record<string, unknown>>;
slugMaps?: Record<string, SlugMap>;
pagesDir?: string;
contentDirs?: Record<string, string>;
i18next?: I18nextOptions;
}
FieldDescription
translationsTranslation objects per locale
slugMapsManual slug maps (merged with auto-discovered)
pagesDirPages directory for auto-discovery
contentDirsContent directories for slug auto-discovery
i18nexti18next plugins and options

I18nInstance

The shape of the i18n helpers object (matches virtual:i18n exports).

interface I18nInstance {
t: (locale: string, key: string) => string;
localePath: (locale: string, path: string) => string;
switchLocalePath: (currentPath: string, targetLocale: string) => string;
getLocaleFromPath: (pathname: string) => string;
localized: <T>(field: Record<string, T>, locale: string) => T;
getLocalizedSlug: (category: string, canonicalSlug: string, locale: string) => string;
getCanonicalSlug: (category: string, localizedSlug: string, locale: string) => string | undefined;
}