import { type HandleOptions } from "./hooks/handle.server.js"; import { type ExcludeConfig } from "./exclude.js"; import { type PathDefinitionTranslations } from "@inlang/paraglide-js/internal/adapter-utils"; import type { ParamMatcher } from "@sveltejs/kit"; import type { UserPathTranslations } from "./config/pathTranslations.js"; import type { Paraglide } from "./runtime.js"; export type I18nUserConfig = { /** * The default languageTag to use if no locale is specified. * By default the sourceLanguageTag from the Paraglide runtime is used. * * @default runtime.sourceLanguageTag */ defaultLanguageTag?: T; /** * The translations for pathnames. * They should **not** include the base path or the language tag. * * You can include parameters in the pathnames by using square brackets. * If you are using a parameter, you must include it in all translations. * * If you are using translated pathnames, make sure you have the `i18n.reroute()` hook registered in your `src/hooks.js` file. * * @example * ```ts * pathnames: { * "/about": { * de: "/ueber-uns", * en: "/about", * fr: "/a-propos", * }, * "/users/[slug]": { * en: "/users/[slug]", * // parameters don't have to be their own path-segment * de: "/benutzer-[slug]", * // parameters don't have to be in the same position * fr: "/[slug]/utilisateurs", * }, * } * ``` */ pathnames?: UserPathTranslations; /** * The matchers for parameters in the pathnames. * You only need to provide these if you are using the parameter-matchers in the pathnames. */ matchers?: Record; /** * A list of paths to exclude from translation. You can use strings or regular expressions. * * Any path that matches one of the strings or regular expressions will not be translated, * meaning that it won't get the language tag in the path, any links to it won't be translated, * and no alternate links will be generated for it. * * @default [] * * @example * ```ts * exclude: ["/base/admin", /^\/base\/admin\/.* /] * ``` */ exclude?: ExcludeConfig; /** * Whether to prefix the language tag to the path even if it's the default language. * * - If set to `"always"`, the language tag will always be included in the path. (eg `/base/en/about`) * - If set to `"never"`, the default language will not have a language tag in the path. (eg `/base/about`) * * @default "never" */ prefixDefaultLanguage?: "always" | "never"; /** * The associated text-direction for each language. It's recommended to set this to avoid * any direction-detection differences between different browsers. * * @default Guesses the direction based on the language tag using `Intl.Locale` * * @example * ```ts * dir: { * en: "ltr", * de: "ltr", * ar: "rtl", * } * ``` */ textDirection?: Record; /** * SEO related options. */ seo?: { /** * Whether to generate alternate links for each page & language and add them to the head. * @default true */ noAlternateLinks?: boolean; }; }; /** * The _resolved_ configuration for the i18n instance. */ export type I18nConfig = { runtime: Paraglide; translations: PathDefinitionTranslations; exclude: (path: string) => boolean; defaultLanguageTag: T; matchers: Record; prefixDefaultLanguage: "always" | "never"; textDirection: Record; seo: { noAlternateLinks: boolean; }; }; /** * Creates an i18n instance that manages your internationalization. * * @param runtime The Paraglide runtime. * @param options The options for the i18n instance. * @returns An i18n instance. * * @example * ```ts * // src/lib/i18n.js * import * as runtime from "../paraglide/runtime.js" * import { createI18n } from "@inlang/paraglide-sveltekit" * * export const i18n = createI18n(runtime, { ...options }) * ``` */ export declare function createI18n(runtime: Paraglide, options?: I18nUserConfig): { /** * The configuration that was used to create this i18n instance. */ config: I18nConfig; /** * The routing strategy that's being used. * * @private Not part of the public API, may change in non-major versions */ strategy: { getLanguageFromLocalisedPath: (localisedPath: string) => T | undefined; getLocalisedPath: (canonicalPath: string, languageTag: T) => string; getCanonicalPath: (localisedPath: string, languageTag: T) => string; }; /** * Returns a `reroute` hook that applies the path translations to the paths. * Register it in your `src/hooks.js` file to enable path translations. * * @example * ```ts * // src/hooks.js * import { i18n } from "../lib/i18n.js" * export const reroute = i18n.reroute() * ``` */ reroute: () => import("@sveltejs/kit").Reroute; /** * Returns a `handle` hook that set's the correct `lang` attribute * on the `html` element * * SERVER ONLY */ handle: (options?: HandleOptions) => import("@sveltejs/kit").Handle; /** * Takes in a URL and returns the language that should be used for it. * * @param url * @returns */ getLanguageFromUrl(url: URL): T; /** * Takes in a route and returns a translated version of it. * This is useful for use in `goto` statements and `redirect` calls. * * The oposite of `i18n.route()`. * * @param canonicalPath The path to translate (eg _/base/about_) * @param lang The language to translate to - Defaults to the current language * @returns The translated path (eg _/base/de/ueber-uns_) * * @example * ```ts * redirect(i18n.resolveRoute("/base/about", "de")) * ``` */ resolveRoute(path: string, lang?: T | undefined): string; /** * Takes in a path in one language and returns it's canonical version. * The oposite of `i18n.resolveRoute()`. * This is useful for use in: * - Language Switchers * - Navigation * * @param targetedPathSource The path to translate (eg _/base/de/ueber-uns_) * @returns The canonical version path (eg _/base/about_) * * @example * ```ts * * ``` */ route(translatedPath: string): string; }; export type I18n = ReturnType>; //# sourceMappingURL=adapter.server.d.ts.map