DuskI18nRoutingConfig
i18n.routing of dusk.config.ts: declaring it turns on automatic locale routing (a locale middleware, the redirects, <html lang dir>, the hreflang links and the client sync).
i18n.routing of dusk.config.ts: declaring it turns on automatic locale routing (a locale middleware, the redirects,
<html lang dir>, the hreflang links and the client sync). Every key but instance has a default.
Import#
ts
import type { DuskI18nRoutingConfig } from "@shadow-js/dusk/vite";
Signature#
ts
interface DuskI18nRoutingConfig {
/** The module that exports the app's i18n instance (build time). */
readonly instance: LocaleInstanceConfig;
/** How URLs carry the locale. Default `"as-needed"`. It must equal the `prefix` the instance was created with. */
readonly prefix?: LocalePrefixMode;
/**
* Where the locale is read from when the URL does not name one, in order; the URL prefix always comes first under
* `"as-needed"` and `"always"`. Default `["cookie", "accept-language"]`. `[]` means the default locale.
*/
readonly detection?: readonly LocaleDetectionSource[];
/**
* The cookie that remembers the locale a URL chose: `SameSite=Lax`, `Path=/`, readable by scripts, `Secure` on https.
* Default `{ name: "locale", maxAge: 31536000 }` (one year). `false` writes none (the `"cookie"` source then reads a
* cookie named `locale`, which the app may write itself).
*/
readonly cookie?: false | { readonly name?: string; readonly maxAge?: number };
/** Write `hreflang` alternate links and a canonical link into the head of every localized page. Default `true`. */
readonly alternates?: boolean;
/**
* The origin of the `hreflang` and canonical URLs (`https://example.com`). Default: the origin of the request, which
* the host check (`security.allowedHosts`) guards.
*/
readonly origin?: string;
}
Members#
| Name | Type | Description |
|---|---|---|
instance |
readonly instance: LocaleInstanceConfig |
The module that exports the app's i18n instance (build time). |
prefix? |
readonly prefix?: LocalePrefixMode |
How URLs carry the locale. Default "as-needed". It must equal the prefix the instance was created with. |
detection? |
readonly detection?: readonly LocaleDetectionSource[] |
Where the locale is read from when the URL does not name one, in order; the URL prefix always comes first under "as-needed" and "always". Default ["cookie", "accept-language"]. [] means the default locale. |
cookie? |
readonly cookie?: false | { readonly name?: string; readonly maxAge?: number } |
The cookie that remembers the locale a URL chose: SameSite=Lax, Path=/, readable by scripts, Secure on https. Default { name: "locale", maxAge: 31536000 } (one year). false writes none (the "cookie" source then reads a cookie named locale, which the app may write itself). |
alternates? |
readonly alternates?: boolean |
Write hreflang alternate links and a canonical link into the head of every localized page. Default true. |
origin? |
readonly origin?: string |
The origin of the hreflang and canonical URLs (https://example.com). Default: the origin of the request, which the host check (security.allowedHosts) guards. |
Examples#
ts
const routing: DuskI18nRoutingConfig = {
instance: { module: "./src/i18n" },
prefix: "as-needed",
detection: ["cookie", "accept-language"],
cookie: { name: "locale", maxAge: 31_536_000 },
};