部分菜单实现中英文切换

This commit is contained in:
GoEdgeLab
2023-12-12 11:47:41 +08:00
parent 1184806fe0
commit 6e84415262
12 changed files with 93 additions and 4 deletions

View File

@@ -0,0 +1,17 @@
package lang
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
Prefix("/settings/lang").
Post("/switch", new(SwitchAction)).
EndAll()
})
}

View File

@@ -0,0 +1,33 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package lang
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"net/http"
)
type SwitchAction struct {
actionutils.ParentAction
}
func (this *SwitchAction) Init() {
this.Nav("", "", "")
}
func (this *SwitchAction) RunPost(params struct{}) {
var langCode = this.LangCode()
if len(langCode) == 0 || langCode == "zh-cn" {
langCode = "en-us"
} else {
langCode = "zh-cn"
}
this.AddCookie(&http.Cookie{
Name: "edgelang",
Value: langCode,
Path: "/",
})
this.Success()
}