nuxt/i18n strategies.
There are four supported strategies that affect how app's routes are generated:
With this strategy, your routes won't have a locale prefix added. The locale will be detected & changed without changing the URL. This implies that you have to rely on browser & cookie detection, and implement locale switches by calling the i18n API.
Using this strategy, all of your routes will have a locale prefix added except for the default language.
With this strategy, all routes will have a locale prefix.
This strategy combines both previous strategies behaviours, meaning that you will get URLs with prefixes for every language, but URLs for the default language will also have a non-prefixed version (though the prefixed version will be preferred when detectBrowserLanguage
is enabled).
To configure the strategy, use the strategy
option.
Make sure that you have a defaultLocale
defined, especially if using prefix_except_default
, prefix_and_default
or no_prefix
strategy. For other strategies it's also recommended to set it as it's gonna be used as a fallback when attempting to redirect from 404 page.
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en'
}
Nuxt
version lower than 2.10.2, and using strategy prefix_except_default
or prefix_and_default
, make sure that that the locale matching defaultLocale
is last in the array of locales. For example:i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
locales: [
'fr',
'en', // Make sure that default locale is the last one!
]
}