feat: sync i18n setting to agent (#8561)

This commit is contained in:
ChengPlay 2025-05-07 10:51:22 +08:00 committed by GitHub
parent 36e0aece06
commit a400caa114
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View file

@ -2,6 +2,7 @@ package i18n
import (
"embed"
"github.com/1Panel-dev/1Panel/agent/app/repo"
"strings"
"github.com/1Panel-dev/1Panel/agent/global"
@ -113,7 +114,7 @@ func UseI18n() gin.HandlerFunc {
return func(context *gin.Context) {
lang := context.GetHeader("Accept-Language")
if lang == "" {
lang = "en"
lang = GetLanguageFromDB()
}
global.I18n = i18n.NewLocalizer(bundle, lang)
}
@ -132,5 +133,17 @@ func Init() {
_, _ = bundle.LoadMessageFileFS(fs, "lang/ru.yaml")
_, _ = bundle.LoadMessageFileFS(fs, "lang/ms.yaml")
_, _ = bundle.LoadMessageFileFS(fs, "lang/ko.yaml")
global.I18n = i18n.NewLocalizer(bundle, "en")
lang := GetLanguageFromDB()
global.I18n = i18n.NewLocalizer(bundle, lang)
}
func GetLanguageFromDB() string {
if global.DB == nil {
return "en"
}
lang, _ := repo.NewISettingRepo().GetValueByKey("Language")
if lang == "" {
return "en"
}
return lang
}

View file

@ -3,6 +3,8 @@ package server
import (
"crypto/tls"
"fmt"
"github.com/1Panel-dev/1Panel/agent/init/log"
"github.com/1Panel-dev/1Panel/agent/init/migration"
"net"
"net/http"
"os"
@ -19,8 +21,6 @@ import (
"github.com/1Panel-dev/1Panel/agent/init/db"
"github.com/1Panel-dev/1Panel/agent/init/dir"
"github.com/1Panel-dev/1Panel/agent/init/hook"
"github.com/1Panel-dev/1Panel/agent/init/log"
"github.com/1Panel-dev/1Panel/agent/init/migration"
"github.com/1Panel-dev/1Panel/agent/init/router"
"github.com/1Panel-dev/1Panel/agent/init/validator"
"github.com/1Panel-dev/1Panel/agent/init/viper"
@ -32,11 +32,11 @@ import (
func Start() {
viper.Init()
dir.Init()
i18n.Init()
log.Init()
db.Init()
cache.Init()
migration.Init()
i18n.Init()
cache.Init()
app.Init()
validator.Init()
gin.SetMode("debug")