diff --git a/islands/Settings.tsx b/islands/Settings.tsx index ae37d67..f2e1eed 100644 --- a/islands/Settings.tsx +++ b/islands/Settings.tsx @@ -9,7 +9,7 @@ import { ConfigType } from "../config.ts"; import SettingsCheckbox from "../components/SettingsCheckbox.tsx"; import SettingsContext from "../components/SettingsContext.tsx"; import SettingsText from "../components/SettingsText.tsx"; -import { i18n_map } from "../server/i18n.ts"; +import t from "../server/i18n.ts"; export type SettingsProps = { show: boolean; @@ -53,7 +53,7 @@ export default class Settings extends Component { }; const loadData = () => { fetchSettings().catch((e) => { - set_error("Failed to fetch settings."); + set_error(t("settings.failed")); console.error(e); }); }; @@ -71,7 +71,7 @@ export default class Settings extends Component { const dlg = useRef(); const showDlg = () => { if (!changed.size) { - show_snack("Nothing was changed."); + show_snack(t("settings.no_changed")); return; } dlg.current?.MDComponent?.show(); @@ -81,14 +81,13 @@ export default class Settings extends Component { saveSettings().then((d) => { set_disabled(false); show_snack( - "Saved." + - (d.is_unsafe - ? " Some settings require a restart to take effect." - : ""), + t("settings.saved") + + (d.is_unsafe ? t("settings.need_restart") : ""), ); + loadData(); }).catch((e) => { set_disabled(false); - show_snack("Failed to save settings."); + show_snack(t("settings.failed")); console.error(e); }); }; @@ -101,28 +100,28 @@ export default class Settings extends Component { @@ -136,60 +135,62 @@ export default class Settings extends Component { } }} > - Use current browser's user agent. + {t("settings.ua_now")} - - + + - - Do you want to save settings? - + {t("settings.save_dlg")} - Yes + {t("common.yes")} - No + {t("common.no")} ); } else { - data =
Loading...
; + data =
{t("common.loading")}
; } return (
diff --git a/server/i18ns.ts b/server/i18ns.ts index dd8d8da..0e6e6d6 100644 --- a/server/i18ns.ts +++ b/server/i18ns.ts @@ -6,8 +6,8 @@ import { pick } from "accept-language-parser/"; const whole_maps = new Map(); const LANGUAGES = ["zh-cn"]; -type MODULE = "common"; -const MODULES: MODULE[] = ["common"]; +type MODULE = "common" | "settings"; +const MODULES: MODULE[] = ["common", "settings"]; export async function load_translation(signal?: AbortSignal) { const base = import.meta.resolve("../translation").slice(8); diff --git a/translation/en/common.jsonc b/translation/en/common.jsonc index 2f6bad2..a7dae35 100644 --- a/translation/en/common.jsonc +++ b/translation/en/common.jsonc @@ -1,3 +1,8 @@ { - "title": "EH Downloader" + "title": "EH Downloader", + "loading": "Loading...", + "reload": "Reload", + "save": "Save", + "yes": "Yes", + "no": "No" } diff --git a/translation/en/settings.jsonc b/translation/en/settings.jsonc new file mode 100644 index 0000000..e849aa6 --- /dev/null +++ b/translation/en/settings.jsonc @@ -0,0 +1,19 @@ +{ + "no_changed": "Nothing was changed.", + "saved": "Saved.", + "failed": "Failed to fetch settings.", + "need_restart": " Some settings require a restart to take effect.", + "download_original_img": "Download original images.", + "ex": "Use exhentai.org.", + "mpv": "Fetch page data from Multi-Page Viewer.", + "base": "Download location: ", + "ua": "User Agent: ", + "ua_now": "Use current browser's user agent.", + "cookies": "Cookies: ", + "enter_cookies": "Enter cookies here", + "enter_new_cookies": "Enter new cookies here", + "max_task_count": "Maximum number of parallel tasks: ", + "max_retry_count": "Maximum retry count: ", + "max_download_img_count": "Maximum number of parallel downloads of images: ", + "save_dlg": "Do you want to save settings?" +} diff --git a/translation/zh-cn/common.jsonc b/translation/zh-cn/common.jsonc index 1900e17..ade2b6f 100644 --- a/translation/zh-cn/common.jsonc +++ b/translation/zh-cn/common.jsonc @@ -1,3 +1,8 @@ { - "title": "EH 下载器" + "title": "EH 下载器", + "loading": "加载中…", + "reload": "重新加载", + "save": "保存", + "yes": "是", + "no": "否" } diff --git a/translation/zh-cn/settings.jsonc b/translation/zh-cn/settings.jsonc new file mode 100644 index 0000000..cff76a5 --- /dev/null +++ b/translation/zh-cn/settings.jsonc @@ -0,0 +1,19 @@ +{ + "no_changed": "设置未更改,无需保存。", + "saved": "已保存。", + "failed": "获取设置失败。", + "need_restart": "部分设置需要重启后才能生效。", + "download_original_img": "下载原始画质的图片。", + "ex": "使用exhentai.org。", + "mpv": "从Multi-Page Viewer获取页面数据。", + "base": "下载位置:", + "ua": "用户代理(User Agent):", + "ua_now": "使用当前浏览器的用户代理", + "cookies": "Cookies:", + "enter_cookies": "在此输入Cookies", + "enter_new_cookies": "在此输入新的Cookies", + "max_task_count": "最大并行任务数:", + "max_retry_count": "最大重试次数:", + "max_download_img_count": "最大图片并行下载数:", + "save_dlg": "是否保存设置?" +}