diff --git a/.gitignore b/.gitignore index 1fa65ceb4..fdd72837d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ __debug_bin log_info.log __debug_bin* .log -debian \ No newline at end of file +debiantoughradius-bin diff --git a/app/i18n.go b/app/i18n.go index 49a8a6a85..791c91520 100644 --- a/app/i18n.go +++ b/app/i18n.go @@ -15,6 +15,7 @@ const ( TransLateSettings = "settings" ZhCN = "zh_CN" EnUS = "en_US" + FrFR = "fr_FR" ) func (a *Application) TransDB() (*bolt.DB, error) { @@ -39,6 +40,10 @@ func (a *Application) TransDB() (*bolt.DB, error) { if err != nil { log.Errorf("create en_US bucket: %s", err) } + _, err = tx.CreateBucketIfNotExists([]byte(FrFR)) // ③ + if err != nil { + log.Errorf("create fr_FR bucket: %s", err) + } return nil }) @@ -66,7 +71,7 @@ func (a *Application) GetTranslateLang() string { } func (a *Application) SetTranslateLang(lang string) { - if !common.InSlice(lang, []string{ZhCN, EnUS}) { + if !common.InSlice(lang, []string{ZhCN, EnUS, FrFR}) { return } transdb, err := a.TransDB() @@ -272,7 +277,7 @@ func (a *Application) TranslateUpdate(lang, module, src, value string) string { } func (a *Application) RenderTranslateFiles() { - langs := []string{ZhCN, EnUS} + langs := []string{ZhCN, EnUS, FrFR} for _, lang := range langs { r := a.LoadTranslateDict(lang) os.WriteFile(path.Join(a.appConfig.System.Workdir, "data", "trans_"+lang+".js"), []byte("window.GlobalTrans="+common.ToJson(r)), 0666) @@ -289,7 +294,7 @@ func (a *Application) RemoveTranslateItems(items []TransTable) { return } defer tx.Rollback() - langs := []string{ZhCN, EnUS} + langs := []string{ZhCN, EnUS, FrFR} for _, lang := range langs { b := tx.Bucket([]byte(lang)) if b == nil { diff --git a/app/pagefunc.go b/app/pagefunc.go index 02db6a355..6698e7e33 100644 --- a/app/pagefunc.go +++ b/app/pagefunc.go @@ -29,6 +29,9 @@ func (a *Application) GetTemplateFuncMap() map[string]interface{} { } return "0" }, + "currentlang": func() string { + return a.GetTranslateLang() + }, "moontheme": func() string { theme := a.GetSystemTheme() if theme == "dark" { diff --git a/assets/templates/index.html b/assets/templates/index.html index 2d8ae2b98..43961c465 100644 --- a/assets/templates/index.html +++ b/assets/templates/index.html @@ -117,14 +117,23 @@ } }, { - view: "switch", onLabel: "中文", offLabel: "English", value: "{{zhlang}}", width: 100, + view: "richselect", + value: "{{currentlang}}", + width: 100, + options: [ + { id: "en_US", value: "English" }, + { id: "zh_CN", value: "中文" }, + { id: "fr_FR", value: "Français" } + ], on: { onChange: function (newValue, oldValue, config) { - webix.delay(function () { - webix.ajax().get("/admin/translate/switch/" + newValue).then(function (resp) { - window.location.reload() + if (newValue !== oldValue) { + webix.delay(function () { + webix.ajax().get("/admin/translate/switch/" + newValue).then(function (resp) { + window.location.reload() + }) }) - }) + } } } }, diff --git a/assets/templates/translate.html b/assets/templates/translate.html index f1ef640e4..0277f5b74 100644 --- a/assets/templates/translate.html +++ b/assets/templates/translate.html @@ -11,7 +11,7 @@ { view: "radio", name: "lang", - options: ["zh_CN", "en_US"], + options: ["zh_CN", "en_US", "fr_FR"], label: gtr("Language"), labelWidth: 100, }, diff --git a/controllers/translate/translate.go b/controllers/translate/translate.go index 0fee8a904..04e73f445 100644 --- a/controllers/translate/translate.go +++ b/controllers/translate/translate.go @@ -68,11 +68,17 @@ func InitRouter() { return c.File(lfile) }) - webserver.GET("/admin/translate/switch/:iszh", func(c echo.Context) error { - if c.Param("iszh") == "1" { - app.GApp().SetTranslateLang(app.ZhCN) - } else { - app.GApp().SetTranslateLang(app.EnUS) + webserver.GET("/admin/translate/switch/:lang", func(c echo.Context) error { + lang := c.Param("lang") + // Handle legacy binary switch for backward compatibility + if lang == "1" { + lang = app.ZhCN + } else if lang == "0" { + lang = app.EnUS + } + // Validate the language code + if lang == app.ZhCN || lang == app.EnUS || lang == app.FrFR { + app.GApp().SetTranslateLang(lang) } return c.JSON(http.StatusOK, web.RestSucc("success")) }) @@ -156,6 +162,7 @@ func InitRouter() { app.GApp().Translate(app.ZhCN, form.Module, form.Key, form.Value) app.GApp().Translate(app.EnUS, form.Module, form.Key, form.Value) + app.GApp().Translate(app.FrFR, form.Module, form.Key, form.Value) return c.JSON(http.StatusOK, web.RestSucc("success")) })