diff --git a/internal/data/cache.go b/internal/data/cache.go index 66d3a556..66c9670a 100644 --- a/internal/data/cache.go +++ b/internal/data/cache.go @@ -20,7 +20,7 @@ type cacheRepo struct { func NewCacheRepo(db *gorm.DB) biz.CacheRepo { return &cacheRepo{ - api: api.NewAPI(app.Version), + api: api.NewAPI(app.Version, app.Locale), db: db, } } diff --git a/internal/job/panel_task.go b/internal/job/panel_task.go index e81e4c86..18a1d4ad 100644 --- a/internal/job/panel_task.go +++ b/internal/job/panel_task.go @@ -29,7 +29,7 @@ type PanelTask struct { func NewPanelTask(db *gorm.DB, log *slog.Logger, backup biz.BackupRepo, cache biz.CacheRepo, task biz.TaskRepo, setting biz.SettingRepo) *PanelTask { return &PanelTask{ - api: api.NewAPI(app.Version), + api: api.NewAPI(app.Version, app.Locale), db: db, log: log, backupRepo: backup, diff --git a/internal/service/cli.go b/internal/service/cli.go index 1d7b1df7..b9c48539 100644 --- a/internal/service/cli.go +++ b/internal/service/cli.go @@ -50,7 +50,7 @@ type CliService struct { func NewCliService(t *gotext.Locale, conf *koanf.Koanf, db *gorm.DB, appRepo biz.AppRepo, cache biz.CacheRepo, user biz.UserRepo, setting biz.SettingRepo, backup biz.BackupRepo, website biz.WebsiteRepo, databaseServer biz.DatabaseServerRepo) *CliService { return &CliService{ hr: `+----------------------------------------------------`, - api: api.NewAPI(app.Version), + api: api.NewAPI(app.Version, app.Locale), t: t, conf: conf, db: db, diff --git a/internal/service/dashboard.go b/internal/service/dashboard.go index d845c5a2..b9ada149 100644 --- a/internal/service/dashboard.go +++ b/internal/service/dashboard.go @@ -41,7 +41,7 @@ type DashboardService struct { func NewDashboardService(t *gotext.Locale, conf *koanf.Koanf, task biz.TaskRepo, website biz.WebsiteRepo, appRepo biz.AppRepo, setting biz.SettingRepo, cron biz.CronRepo, backupRepo biz.BackupRepo) *DashboardService { return &DashboardService{ t: t, - api: api.NewAPI(app.Version), + api: api.NewAPI(app.Version, app.Locale), conf: conf, taskRepo: task, websiteRepo: website, diff --git a/pkg/api/api.go b/pkg/api/api.go index 739b8d2a..8d826a23 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -11,8 +11,8 @@ import ( ) type API struct { - panelVersion string - client *resty.Client + panelVersion, locale string + client *resty.Client } type Response struct { @@ -20,7 +20,7 @@ type Response struct { Data any `json:"data"` } -func NewAPI(panelVersion string, url ...string) *API { +func NewAPI(panelVersion, locale string, url ...string) *API { if len(panelVersion) == 0 { panic("panel version is required") } @@ -37,6 +37,7 @@ func NewAPI(panelVersion string, url ...string) *API { client.SetTimeout(10 * time.Second) client.SetBaseURL(url[0]) client.SetHeader("User-Agent", fmt.Sprintf("rat-panel/%s %s/%s", panelVersion, hostInfo.Platform, hostInfo.PlatformVersion)) + client.SetQueryParam("locale", locale) return &API{ panelVersion: panelVersion, diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index 15686dfc..731ddf0f 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -13,7 +13,7 @@ type APITestSuite struct { func TestAPITestSuite(t *testing.T) { suite.Run(t, &APITestSuite{ - api: NewAPI("2.3.0"), + api: NewAPI("2.3.0", "en"), }) }