detectBrowserLanguage
- type:
object
- default:
{ alwaysRedirect: false, fallbackLocale: '', redirectOn: 'root', useCookie: true, cookieCrossOrigin: false, cookieDomain: null, cookieKey: 'i18n_redirected', cookieSecure: false }
Enables browser language detection to automatically redirect visitors to their preferred locale as they visit your site for the first time.
See also Browser language detection for a guide.
Note that for better SEO it's recommended to set
redirectOn
to root
.Supported properties:
alwaysRedirect
(default:false
) - Set to always redirect to the value stored in the cookie, not just on first visit.fallbackLocale
(default:null
) - If none of the locales match the browser's locale, use this one as a fallback.redirectOn
(default:root
) - Supported options:all
- detect browser locale on all paths.root
(recommended for improved SEO) - only detect the browser locale on the root path (/
) of the site. Only effective when using strategy other than'no_prefix'
.no prefix
- a more permissive variant ofroot
that will detect the browser locale on the root path (/
) and also on paths that have no locale prefix (like/foo
). Only effective when using strategy other than'no_prefix'
.
useCookie
(default:true
) - If enabled, a cookie is set once the user has been redirected to browser's preferred locale, to prevent subsequent redirections. Set tofalse
to redirect every time.cookieKey
(default:'i18n_redirected'
) - Cookie name.cookieDomain
(default:null
) - Set to override the default domain of the cookie. Defaults to the host of the site.cookieCrossOrigin
(default:false
) - Whentrue
, sets the flagsSameSite=None; Secure
on the cookie to allow cross-domain use of the cookie (required when app is embedded in an iframe).cookieSecure
(default:false
) - Sets theSecure
flag for the cookie.
Set to false to disable.