mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
Merge pull request #16 from nezhahq/main
refactor: admin language first
This commit is contained in:
commit
773a40ee53
4919
package-lock.json
generated
Normal file
4919
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@ import ErrorPage from "./pages/ErrorPage"
|
|||||||
import NotFound from "./pages/NotFound"
|
import NotFound from "./pages/NotFound"
|
||||||
import Server from "./pages/Server"
|
import Server from "./pages/Server"
|
||||||
import ServerDetail from "./pages/ServerDetail"
|
import ServerDetail from "./pages/ServerDetail"
|
||||||
|
import { useTranslation } from "react-i18next"
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const { data: settingData, error } = useQuery({
|
const { data: settingData, error } = useQuery({
|
||||||
@ -18,6 +19,7 @@ const App: React.FC = () => {
|
|||||||
refetchOnMount: true,
|
refetchOnMount: true,
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
})
|
})
|
||||||
|
const { i18n } = useTranslation()
|
||||||
|
|
||||||
const InjectContext = useCallback((content: string) => {
|
const InjectContext = useCallback((content: string) => {
|
||||||
const tempDiv = document.createElement("div")
|
const tempDiv = document.createElement("div")
|
||||||
@ -46,7 +48,7 @@ const App: React.FC = () => {
|
|||||||
Array.from(tempDiv.childNodes).forEach((node) => {
|
Array.from(tempDiv.childNodes).forEach((node) => {
|
||||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||||
const element = node as HTMLElement
|
const element = node as HTMLElement
|
||||||
;(handlers[element.tagName] || handlers.DEFAULT)(element)
|
; (handlers[element.tagName] || handlers.DEFAULT)(element)
|
||||||
} else if (node.nodeType === Node.TEXT_NODE) {
|
} else if (node.nodeType === Node.TEXT_NODE) {
|
||||||
document.body.appendChild(document.createTextNode(node.textContent || ""))
|
document.body.appendChild(document.createTextNode(node.textContent || ""))
|
||||||
}
|
}
|
||||||
@ -61,6 +63,10 @@ const App: React.FC = () => {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settingData?.data?.language && !localStorage.getItem("language")) {
|
||||||
|
i18n.changeLanguage(settingData?.data?.language)
|
||||||
|
}
|
||||||
|
|
||||||
if (settingData?.data?.custom_code) {
|
if (settingData?.data?.custom_code) {
|
||||||
InjectContext(settingData?.data?.custom_code)
|
InjectContext(settingData?.data?.custom_code)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ function Header() {
|
|||||||
const siteName = settingData?.data?.site_name
|
const siteName = settingData?.data?.site_name
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = siteName || "NEZHA"
|
document.title = siteName || "哪吒监控 Nezha Monitoring"
|
||||||
}, [siteName])
|
}, [siteName])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -23,7 +23,7 @@ export function LanguageSwitcher() {
|
|||||||
const localeItems = [
|
const localeItems = [
|
||||||
{ name: t("language.zh-CN"), code: "zh-CN" },
|
{ name: t("language.zh-CN"), code: "zh-CN" },
|
||||||
{ name: t("language.zh-TW"), code: "zh-TW" },
|
{ name: t("language.zh-TW"), code: "zh-TW" },
|
||||||
{ name: t("language.en"), code: "en" },
|
{ name: t("language.en-US"), code: "en-US" },
|
||||||
]
|
]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -6,7 +6,7 @@ import zhCNTranslation from "./locales/zh-CN/translation.json"
|
|||||||
import zhTWTranslation from "./locales/zh-TW/translation.json"
|
import zhTWTranslation from "./locales/zh-TW/translation.json"
|
||||||
|
|
||||||
const resources = {
|
const resources = {
|
||||||
en: {
|
"en-US": {
|
||||||
translation: enTranslation,
|
translation: enTranslation,
|
||||||
},
|
},
|
||||||
"zh-CN": {
|
"zh-CN": {
|
||||||
@ -18,13 +18,13 @@ const resources = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getStoredLanguage = () => {
|
const getStoredLanguage = () => {
|
||||||
return localStorage.getItem("language") || "en"
|
return localStorage.getItem("language") || "en-US"
|
||||||
}
|
}
|
||||||
|
|
||||||
i18n.use(initReactI18next).init({
|
i18n.use(initReactI18next).init({
|
||||||
resources,
|
resources,
|
||||||
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
|
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
|
||||||
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
|
fallbackLng: "en-US", // 当前语言的翻译没有找到时,使用的备选语言
|
||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false, // react已经安全地转义
|
escapeValue: false, // react已经安全地转义
|
||||||
},
|
},
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
"language": {
|
"language": {
|
||||||
"zh-CN": "简体中文",
|
"zh-CN": "简体中文",
|
||||||
"zh-TW": "繁體中文",
|
"zh-TW": "繁體中文",
|
||||||
"en": "English"
|
"en-US": "English"
|
||||||
},
|
},
|
||||||
"theme": {
|
"theme": {
|
||||||
"light": "Light",
|
"light": "Light",
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
"language": {
|
"language": {
|
||||||
"zh-CN": "简体中文",
|
"zh-CN": "简体中文",
|
||||||
"zh-TW": "繁體中文",
|
"zh-TW": "繁體中文",
|
||||||
"en": "English"
|
"en-US": "English"
|
||||||
},
|
},
|
||||||
"theme": {
|
"theme": {
|
||||||
"light": "亮色",
|
"light": "亮色",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user