Skip to content

Commit 63bb672

Browse files
committed
fix(I18n): Translation supplement
Translation supplement, automatic lanSupplement the missing translations
1 parent 5c0c358 commit 63bb672

File tree

8 files changed

+34
-31
lines changed

8 files changed

+34
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"cmdk": "^1.0.0",
3535
"copy-to-clipboard": "^3.3.3",
3636
"i18next": "^24.0.2",
37+
"i18next-browser-languagedetector": "^8.0.0",
3738
"jotai-zustand": "^0.6.0",
3839
"lucide-react": "^0.454.0",
3940
"next-themes": "^0.3.0",

src/lib/i18n.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import i18n from "i18next";
22
import { initReactI18next } from "react-i18next";
3+
import LanguageDetector from "i18next-browser-languagedetector";
34

45
import enTranslation from "../locales/en/translation.json";
56
import itTranslation from "../locales/it/translation.json";
@@ -21,22 +22,16 @@ const resources = {
2122
},
2223
};
2324

24-
const getStoredLanguage = () => {
25-
return localStorage.getItem("language") || "zh-CN";
26-
};
2725

28-
i18n.use(initReactI18next).init({
29-
resources,
30-
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
31-
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
32-
interpolation: {
33-
escapeValue: false, // react已经安全地转义
34-
},
35-
});
26+
i18n.use(initReactI18next)
27+
.use(LanguageDetector)
28+
.init({
29+
resources,
30+
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
31+
interpolation: {
32+
escapeValue: false, // react已经安全地转义
33+
},
34+
});
3635

37-
// 添加语言改变时的处理函数
38-
i18n.on("languageChanged", (lng) => {
39-
localStorage.setItem("language", lng);
40-
});
4136

4237
export default i18n;

src/locales/en/translation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"WAF": "Web application firewall",
126126
"SiteName": "Site name",
127127
"DashboardOriginalHost": "Dashboard Server Domain/IP without CDN",
128-
"Auto": "automatic recognition",
128+
"Auto": "Automatic",
129129
"LoginFailed": "Login failed",
130130
"BruteForceAttackingToken": "Brute Force Attacking Token",
131131
"BruteForceAttackingAgentSecret": "Brute Force Attacking Agent Secret",
@@ -150,4 +150,4 @@
150150
"Count": "Count",
151151
"LastBlockReason": "Last Block Reason",
152152
"LastBlockTime": "Last ban time"
153-
}
153+
}

src/locales/it/translation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"TasksToTriggerAfterRecovery": "Attività da attivare dopo il ripristino",
6969
"Confirm": "Confermo",
7070
"ConfirmDeletion": "Confermi l'eliminazione?",
71-
"NewService": "Nuovo servizio",
7271
"Services": "Servizi",
7372
"ShowInService": "Mostra in servizio",
7473
"Coverages": {
@@ -126,6 +125,7 @@
126125
"CreateService": "Crea servizio",
127126
"EditTask": "Modifica attività",
128127
"CreateTask": "Crea attività",
128+
"Auto": "automatico",
129129
"CreateNotifier": "Crea notifica",
130130
"EditNotifier": "Modifica notifica",
131131
"EditAlertRule": "Modifica le regole degli allarmi",
@@ -150,4 +150,4 @@
150150
"Count": "contare",
151151
"LastBlockReason": "Motivo dell'ultimo divieto",
152152
"LastBlockTime": "L'ultima volta che è stato vietato"
153-
}
153+
}

src/locales/zh-CN/translation.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"TasksToTriggerAfterRecovery": "恢复后要触发的任务",
6969
"Confirm": "确认",
7070
"ConfirmDeletion": "确认删除?",
71-
"NewService": "新服务",
7271
"Services": "服务",
7372
"ShowInService": "服务中显示",
7473
"Coverages": {
@@ -149,5 +148,6 @@
149148
"NewUser": "新用户",
150149
"Count": "计数",
151150
"LastBlockReason": "最后封禁原因",
152-
"LastBlockTime": "最后封禁时间"
153-
}
151+
"LastBlockTime": "最后封禁时间",
152+
"Auto": "自动"
153+
}

src/locales/zh-TW/translation.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"TasksToTriggerAfterRecovery": "恢復後要觸發的任務",
6969
"Confirm": "確認",
7070
"ConfirmDeletion": "確認刪除?",
71-
"NewService": "新服務",
7271
"Services": "服務",
7372
"ShowInService": "服務中顯示",
7473
"Coverages": {
@@ -149,5 +148,6 @@
149148
"NewUser": "新用戶",
150149
"Count": "計數",
151150
"LastBlockReason": "最後封鎖原因",
152-
"LastBlockTime": "最後封鎖時間"
153-
}
151+
"LastBlockTime": "最後封鎖時間",
152+
"Auto": "自動"
153+
}

src/routes/settings.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const settingFormSchema = z.object({
4848
});
4949

5050
export default function SettingsPage() {
51-
const { t } = useTranslation();
51+
const { t , i18n} = useTranslation();
5252
const [config, setConfig] = useState<ModelConfig>();
5353
const [error, setError] = useState<Error>();
5454

@@ -106,6 +106,11 @@ export default function SettingsPage() {
106106
return;
107107
} finally {
108108
toast(t("Success"));
109+
if (values.language!= "auto"){
110+
i18n.changeLanguage(values.language)
111+
}else{
112+
i18n.changeLanguage(i18n.services.languageDetector.detect());
113+
}
109114
}
110115
};
111116

src/types/settings.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import i18next from "i18next";
12
export const settingCoverageTypes: Record<number, string> = {
2-
1: "All excludes specific servers",
3-
2: "Only specific servers",
3+
1: i18next.t("Coverages.Excludes"),
4+
2: i18next.t("Coverages.Only"),
45
}
56

67
export const nezhaLang: Record<string, string> = {
8+
"auto": i18next.t("Auto"),
79
"zh_CN": "简体中文(中国大陆)",
810
"zh_TW": "正體中文(台灣)",
911
"en_US": "English",
1012
}
1113

1214
export const wafBlockReasons: Record<number, string> = {
13-
1: "Login failed",
14-
2: "Brute-force attacking token",
15-
3: "Brute-force attacking Agent secret",
15+
1: i18next.t("LoginFailed"),
16+
2: i18next.t("BruteForceAttackingToken"),
17+
3: i18next.t("BruteForceAttackingAgentSecret"),
1618
}

0 commit comments

Comments
 (0)