From 134afd7b8e66c4b570c9fcd4d16d9c7529bb510d Mon Sep 17 00:00:00 2001
From: Kenneth <16360559+YesYouKenSpace@users.noreply.github.com>
Date: Tue, 18 Feb 2025 17:00:05 +0800
Subject: [PATCH 1/2] feat(localization): introduce localization to 404 texts
---
components/SEO.js | 2 +-
lib/lang/en-US.js | 4 +++-
lib/lang/zh-CN.js | 4 +++-
themes/fukasawa/index.js | 3 ++-
themes/game/index.js | 3 ++-
themes/gitbook/index.js | 3 ++-
6 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/components/SEO.js b/components/SEO.js
index cd7d78c6..7f0cc0c2 100644
--- a/components/SEO.js
+++ b/components/SEO.js
@@ -247,7 +247,7 @@ const getSEOMeta = (props, router, locale) => {
}
case '/404':
return {
- title: `${siteInfo?.title} | 页面找不到啦`,
+ title: `${siteInfo?.title} | ${locale.NAV.PAGE_NOT_FOUND}`,
image: `${siteInfo?.pageCover}`
}
case '/tag':
diff --git a/lib/lang/en-US.js b/lib/lang/en-US.js
index 1649c6d3..7229a152 100644
--- a/lib/lang/en-US.js
+++ b/lib/lang/en-US.js
@@ -17,7 +17,9 @@ export default {
NAVIGATOR: 'NAV',
ABOUT: 'About',
MAIL: 'E-Mail',
- ARCHIVE: 'Archive'
+ ARCHIVE: 'Archive',
+ PAGE_NOT_FOUND: 'Page Not Found',
+ PAGE_NOT_FOUND_REDIRECT: 'Page Not Found, Redirecting to Home Page...'
},
COMMON: {
THEME: 'Theme',
diff --git a/lib/lang/zh-CN.js b/lib/lang/zh-CN.js
index 265bb0c2..f51b6ba5 100644
--- a/lib/lang/zh-CN.js
+++ b/lib/lang/zh-CN.js
@@ -17,7 +17,9 @@ export default {
ABOUT: '关于',
NAVIGATOR: '导航',
MAIL: '邮箱',
- ARCHIVE: '归档'
+ ARCHIVE: '归档',
+ PAGE_NOT_FOUND: '页面找不到啦',
+ PAGE_NOT_FOUND_REDIRECT: '页面无法加载,即将返回首页'
},
COMMON: {
THEME: 'Theme',
diff --git a/themes/fukasawa/index.js b/themes/fukasawa/index.js
index 5553167c..4176ed11 100644
--- a/themes/fukasawa/index.js
+++ b/themes/fukasawa/index.js
@@ -215,6 +215,7 @@ const LayoutArchive = props => {
*/
const Layout404 = props => {
const router = useRouter()
+ const { locale } = useGlobal()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
@@ -232,7 +233,7 @@ const Layout404 = props => {
404
-
页面无法加载,即将返回首页
+ {locale.NAV.PAGE_NOT_FOUND_REDIRECT}
diff --git a/themes/game/index.js b/themes/game/index.js
index cd46246a..07db77df 100644
--- a/themes/game/index.js
+++ b/themes/game/index.js
@@ -354,6 +354,7 @@ const LayoutSlug = props => {
*/
const Layout404 = props => {
const router = useRouter()
+ const { locale } = useGameGlobal()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
@@ -371,7 +372,7 @@ const Layout404 = props => {
404
-
页面无法加载,即将返回首页
+ {locale.NAV.PAGE_NOT_FOUND_REDIRECT}
diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js
index 2da36965..13014b72 100644
--- a/themes/gitbook/index.js
+++ b/themes/gitbook/index.js
@@ -438,6 +438,7 @@ const LayoutArchive = props => {
*/
const Layout404 = props => {
const router = useRouter()
+ const { locale } = useGlobal()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
@@ -455,7 +456,7 @@ const Layout404 = props => {
404
-
页面无法加载,即将返回首页
+ {locale.NAV.PAGE_NOT_FOUND_REDIRECT}
From 504f5fbac1bb21e8849b85d33c4d2e8a892c5541 Mon Sep 17 00:00:00 2001
From: "tangly1024.com"
Date: Fri, 14 Mar 2025 16:39:38 +0800
Subject: [PATCH 2/2] theme game locale 404
---
themes/game/index.js | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/themes/game/index.js b/themes/game/index.js
index 07db77df..a2ad09e0 100644
--- a/themes/game/index.js
+++ b/themes/game/index.js
@@ -6,9 +6,11 @@ import NotionPage from '@/components/NotionPage'
import { PWA as initialPWA } from '@/components/PWA'
import ShareBar from '@/components/ShareBar'
import { siteConfig } from '@/lib/config'
+import { useGlobal } from '@/lib/global'
import { loadWowJS } from '@/lib/plugins/wow'
import { deepClone, isBrowser, shuffleArray } from '@/lib/utils'
import Link from 'next/link'
+import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useRef, useState } from 'react'
import Announcement from './components/Announcement'
import { ArticleLock } from './components/ArticleLock'
@@ -30,7 +32,6 @@ import SideBarContent from './components/SideBarContent'
import SideBarDrawer from './components/SideBarDrawer'
import CONFIG from './config'
import { Style } from './style'
-import { useRouter } from 'next/router'
// const AlgoliaSearchModal = dynamic(() => import('@/components/AlgoliaSearchModal'), { ssr: false })
@@ -354,7 +355,7 @@ const LayoutSlug = props => {
*/
const Layout404 = props => {
const router = useRouter()
- const { locale } = useGameGlobal()
+ const { locale } = useGlobal()
useEffect(() => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
@@ -367,16 +368,21 @@ const Layout404 = props => {
}, 3000)
}, [])
- return <>
-
-
-
404
-
-
{locale.NAV.PAGE_NOT_FOUND_REDIRECT}
-
-
+ return (
+ <>
+
+
+
+
+ 404
+
+
+
{locale.NAV.PAGE_NOT_FOUND_REDIRECT}
+
+
>
+ )
}
/**