mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 07:26:47 +00:00
根据url中的语言前缀,处理站点显示的翻译语言
This commit is contained in:
@@ -89,29 +89,7 @@ export function GlobalContextProvider(props) {
|
||||
|
||||
// 添加路由变化时的语言处理
|
||||
useEffect(() => {
|
||||
const handleRouteChange = (url) => {
|
||||
// 从路径中提取语言前缀
|
||||
const pathSegments = url.split('/')
|
||||
const pathLang = pathSegments[1]
|
||||
|
||||
// 检查是否是有效的语言路径
|
||||
if (pathLang === 'en' || pathLang === 'zh') {
|
||||
const targetLang = pathLang === 'en' ? 'en-US' : 'zh-CN'
|
||||
|
||||
// 直接更新语言,不使用 localStorage
|
||||
updateLang(targetLang)
|
||||
updateLocale(generateLocaleDict(targetLang))
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化时处理当前路径
|
||||
handleRouteChange(router.asPath)
|
||||
|
||||
// 监听路由变化
|
||||
router.events.on('routeChangeComplete', handleRouteChange)
|
||||
return () => {
|
||||
router.events.off('routeChangeComplete', handleRouteChange)
|
||||
}
|
||||
initLocale(router.locale, changeLang, updateLocale)
|
||||
}, [router])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user