Merge pull request #16 from nezhahq/main

refactor: admin language first
This commit is contained in:
仓鼠 2024-12-15 16:13:25 +08:00 committed by GitHub
commit 773a40ee53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 4933 additions and 8 deletions

4919
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@ import ErrorPage from "./pages/ErrorPage"
import NotFound from "./pages/NotFound"
import Server from "./pages/Server"
import ServerDetail from "./pages/ServerDetail"
import { useTranslation } from "react-i18next"
const App: React.FC = () => {
const { data: settingData, error } = useQuery({
@ -18,6 +19,7 @@ const App: React.FC = () => {
refetchOnMount: true,
refetchOnWindowFocus: true,
})
const { i18n } = useTranslation()
const InjectContext = useCallback((content: string) => {
const tempDiv = document.createElement("div")
@ -61,6 +63,10 @@ const App: React.FC = () => {
return null
}
if (settingData?.data?.language && !localStorage.getItem("language")) {
i18n.changeLanguage(settingData?.data?.language)
}
if (settingData?.data?.custom_code) {
InjectContext(settingData?.data?.custom_code)
}

View File

@ -24,7 +24,7 @@ function Header() {
const siteName = settingData?.data?.site_name
useEffect(() => {
document.title = siteName || "NEZHA"
document.title = siteName || "哪吒监控 Nezha Monitoring"
}, [siteName])
return (

View File

@ -23,7 +23,7 @@ export function LanguageSwitcher() {
const localeItems = [
{ name: t("language.zh-CN"), code: "zh-CN" },
{ name: t("language.zh-TW"), code: "zh-TW" },
{ name: t("language.en"), code: "en" },
{ name: t("language.en-US"), code: "en-US" },
]
return (

View File

@ -6,7 +6,7 @@ import zhCNTranslation from "./locales/zh-CN/translation.json"
import zhTWTranslation from "./locales/zh-TW/translation.json"
const resources = {
en: {
"en-US": {
translation: enTranslation,
},
"zh-CN": {
@ -18,13 +18,13 @@ const resources = {
}
const getStoredLanguage = () => {
return localStorage.getItem("language") || "en"
return localStorage.getItem("language") || "en-US"
}
i18n.use(initReactI18next).init({
resources,
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
fallbackLng: "en-US", // 当前语言的翻译没有找到时,使用的备选语言
interpolation: {
escapeValue: false, // react已经安全地转义
},

View File

@ -79,7 +79,7 @@
"language": {
"zh-CN": "简体中文",
"zh-TW": "繁體中文",
"en": "English"
"en-US": "English"
},
"theme": {
"light": "Light",

View File

@ -79,7 +79,7 @@
"language": {
"zh-CN": "简体中文",
"zh-TW": "繁體中文",
"en": "English"
"en-US": "English"
},
"theme": {
"light": "亮色",