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