Configuration
Configure the integration
You can pass the following options to the integration.
defaultLocale
(required)
Type: string
Sets the default locale for your website.
locales
(required)
Type: Array<string>
Sets the available locales for your website. Must include the default locale.
strategy
Type: "prefixWithoutDefault" | "prefix"
Default: "prefixWithoutDefault"
Defines how your routes are generated:
-
"prefixWithoutDefault"
will not add a prefix for your default locale:Directorysrc/routes/
- index.astro / and /fr
- about.astro /about and /fr/about
-
"prefix"
will add a prefix for your default locale:Directorysrc/routes/
- index.astro /en and /fr
- about.astro /en/about and /fr/about
pages
Type: Record<string, Record<string, string>>
Allows you to define translated paths for your locales. For example:
Integration configuration:
Project structure
Directorysrc/routes/
- index.astro
- about.astro
- contact.astro
Directoryblog/
- [slug].astro
URL structure
Directory/
- …
- about
- contact
Directoryblog/
- a
- b
Directoryfr/
- a-propos
- contact
Directoryle-blog/
- a
- b
localesDir
Type: string
Default: "./src/locales"
A path relative to the root where locales files are located for translations features.
defaultNamespace
Type: string
Default: "common"
Sets the default namespace for locales. Since this package uses i18next
under the hood, it allows to split
translations data in multiple json files under src/locales/[locale]/
. If you’re not using a file called common.json
,
you need to update this property to have proper types completions when using t
.
Directorysrc/locales/
Directoryen/
- shared.json Update this option to
"shared"
if you’re not using the default"common"
- test.json
- shared.json Update this option to
Directoryfr/
- shared.json
client
Type: false | ClientConfig
Default: false
Client usage is disabled by default because it sends some JavaScript to the browser.
Enabling any of the following features requires importing the <I18nClient/>
component.
ClientConfig
Utility | Required features |
---|---|
t | data , translations |
getLocale | data |
getLocales | data |
getDefaultLocale | data |
getHtmlAttrs | data |
setDynamicParams | N/A, server only |
getLocalePath | data , paths |
switchLocalePath | data , paths |
getSwitcherData | data , paths |
getLocalePlaceholder | N/A, getStaticPaths only |
data
:boolean
, defaults tofalse
paths
:boolean
, defaults tofalse
translations
:boolean
, defaults tofalse
rootRedirect
Type: { status: number; destination: string }
When using strategy: "prefix"
, you may want to redirect your users from the root
to a specific page (likely the default locale root). This option allows you to do so: