detectBrowserLanguage
object
| boolean
{ alwaysRedirect: false, fallbackLocale: '', redirectOn: 'root', useCookie: true, cookieCrossOrigin: false, cookieDomain: null, cookieKey: 'i18n_redirected', cookieSecure: false }
启用浏览器语言检测,以便在访客第一次访问您的网站时自动重定向至他们首选的区域。
有关详细指南,请参见 浏览器语言检测。
redirectOn
设置为 root
。设置为 false
以禁用。
支持的属性:
alwaysRedirect
boolean
false
设置为始终重定向到存储在 cookie 中的值,而不仅仅是在第一次访问时。
fallbackLocale
string
或 null
如果没有任何语言与浏览器的语言匹配,则使用此语言作为后备。
redirectOn
string
root
支持的选项:
all
- 在所有路径上检测浏览器区域。root
(推荐用于改善 SEO) - 仅在网站的根路径(/
) 上检测浏览器区域。仅在使用非 'no_prefix'
策略时有效。no prefix
- 一个更宽许的 root
变体,在根路径(/
) 和没有区域前缀的路径上(如 /foo
)检测浏览器区域。仅在使用非 'no_prefix'
策略时有效。useCookie
boolean
true
如果启用,则在用户被重定向到浏览器首选区域后设置一个 cookie,以防止后续重定向。设置为 false
每次都进行重定向。
cookieKey
string
'i18n_redirected'
Cookie 名称。
cookieDomain
string
或 null
null
设置以覆盖 cookie 的默认域。默认为网站的 主机。
cookieCrossOrigin
boolean
false
当 true
时,在 cookie 上设置标志 SameSite=None; Secure
以允许跨域使用 cookie(在应用嵌入在 iframe 中时需要)。
cookieSecure
boolean
false
为 cookie 设置 Secure
标志。