You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/02.guide/10.multi-domain-locales.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,3 +170,46 @@ The same requests when using the `'prefix_except_default'`{lang="ts-type"} strat
170
170
-https://fr.mydomain.com/en -> https://fr.mydomain.com/en (en language)
171
171
172
172
A locale is only unprefixed on the domains it is the default for, on every other domain it keeps its prefix. This includes the locale set as `defaultLocale`.
173
+
174
+
## Restricting locales to specific domains
175
+
176
+
A locale's `domains` doesn't have to list every domain, it only has to list the domains that locale should be served on. A locale configured without `domains` is served on all of them.
177
+
178
+
```ts [nuxt.config.ts]
179
+
exportdefaultdefineNuxtConfig({
180
+
i18n: {
181
+
locales: [
182
+
{
183
+
code: 'en',
184
+
domains: ['mydomain.com'],
185
+
defaultForDomains: ['mydomain.com']
186
+
},
187
+
{
188
+
// shared between both domains
189
+
code: 'fr',
190
+
domains: ['mydomain.com', 'es.mydomain.com']
191
+
},
192
+
{
193
+
code: 'es',
194
+
domains: ['es.mydomain.com'],
195
+
defaultForDomains: ['es.mydomain.com']
196
+
}
197
+
],
198
+
defaultLocale: 'en',
199
+
strategy: 'prefix_except_default',
200
+
multiDomainLocales: true
201
+
}
202
+
})
203
+
```
204
+
205
+
Given the above configuration, following requests will be:
206
+
-https://mydomain.com -> https://mydomain.com (en language)
-https://es.mydomain.com/en -> https://mydomain.com (en language, redirected to the domain serving it)
212
+
213
+
Locales served on other domains stay available in `locales` and in the locale switcher, `switchLocalePath` links to them on the domain that serves them. Browser language detection only applies locales served on the current domain, so a visitor whose browser or cookie locale isn't available there keeps that domain's own locale.
214
+
215
+
A request on a host that doesn't match any configured domain, such as a staging domain or a health check by IP, isn't restricted. Every locale is served there and `defaultLocale` is used as the unprefixed default, so it's worth setting even when every domain has its own default through `defaultForDomains`.
Copy file name to clipboardExpand all lines: docs/content/docs/04.api/00.options.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,6 +144,7 @@ See also [Multiple files lazy loading](/docs/guide/lazy-load-translations#multip
144
144
145
145
- type: `null | string[]`{lang="ts-type"}
146
146
- An array of `domain`. This property is required when using [`multiDomainLocales`](/docs/api/options#multiDomainLocales) while one or more of the domains having multiple of the same locales
147
+
- This does not have to be the same array for every locale, a locale is only served on the domains listed here. A locale without `domains` is served on all of them. See [Restricting locales to specific domains](/docs/guide/multi-domain-locales#restricting-locales-to-specific-domains)
0 commit comments