Skip to content

Commit

Permalink
switch language on the front end
Browse files Browse the repository at this point in the history
  • Loading branch information
laijinhang authored and cg33 committed Feb 15, 2022
1 parent 62a5a5a commit 0f16580
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
Port: "3306",
User: "root",
Pwd: "root",
Name: "godmin",
Name: "goadmin",
MaxIdleCon: 50,
MaxOpenCon: 150,
Driver: config.DriverMysql,
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ require (
github.com/GoAdminGroup/html v0.0.1
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e
github.com/gin-gonic/gin v1.5.0
github.com/go-sql-driver/mysql v1.5.0
github.com/gogf/gf v1.11.6
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lib/pq v1.3.0
github.com/magiconair/properties v1.8.1
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5E
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GoAdminGroup/html v0.0.1 h1:SdWNWl4OKPsvDk2GDp5ZKD6ceWoN8n4Pj6cUYxavUd0=
github.com/GoAdminGroup/html v0.0.1/go.mod h1:A1laTJaOx8sQ64p2dE8IqtstDeCNBHEazrEp7hR5VvM=
github.com/GoAdminGroup/themes v0.0.27 h1:mm1JBSF2ucK8Yv2PH5w4+gzqisIPo2Q9t4+ICn8460M=
github.com/GoAdminGroup/themes v0.0.27/go.mod h1:ABCOeBeibfg9DxAsGVa1NzYK9/nIbHT/BuFrCRIKo8A=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e/go.mod h1:Bdzq+51GR4/0DIhaICZEOm+OHvXGwwB2trKZ8B4Y6eQ=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
Expand Down Expand Up @@ -87,6 +89,8 @@ github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
Expand Down Expand Up @@ -180,6 +184,8 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c h1:jceGD5YNJGgGMkJz79agzOln1K9TaZUjv5ird16qniQ=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 2 additions & 0 deletions modules/language/cn.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,6 @@ var cn = LangSet{
"admin.basic admin": "基础Admin",
"admin.a built-in plugins of goadmin which help you to build a crud manager platform quickly.": "一个内置GoAdmin插件,帮助您快速搭建curd简易管理后台。",
"admin.official": "GoAdmin官方",

"language": "语言",
}
1 change: 1 addition & 0 deletions modules/language/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,5 @@ var en = LangSet{
"admin.basic admin": "Basic Admin",
"admin.a built-in plugins of goadmin which help you to build a crud manager platform quickly.": "A built-in plugins of GoAdmin which help you to build a crud manager platform quickly.",
"admin.official": "Official",
"language": "Language",
}
6 changes: 6 additions & 0 deletions modules/language/jp.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,10 @@ var jp = LangSet{
"admin.basic admin": "Basic Admin",
"admin.a built-in plugins of goadmin which help you to build a crud manager platform quickly.": "A built-in plugins of GoAdmin which help you to build a crud manager platform quickly.",
"admin.official": "Official",

"used for login": "ログインに使用",
"used to display": "表示に使用",
"a path a line": "パスの文字列",

"language": "言語",
}
1 change: 1 addition & 0 deletions modules/language/tc.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,5 @@ var tc = LangSet{
"admin.basic admin": "基礎Admin",
"admin.a built-in plugins of goadmin which help you to build a crud manager platform quickly.": "壹個內置GoAdmin插件,幫助您快速搭建curd簡易管理後臺。",
"admin.official": "GoAdmin官方",
"language": "語言",
}
16 changes: 1 addition & 15 deletions plugins/admin/controller/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/url"

"github.com/GoAdminGroup/go-admin/modules/language"
"github.com/GoAdminGroup/go-admin/modules/logger"

"github.com/GoAdminGroup/go-admin/template"
Expand All @@ -14,10 +15,7 @@ import (

"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/modules/auth"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/modules/file"
"github.com/GoAdminGroup/go-admin/modules/language"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
form2 "github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
Expand Down Expand Up @@ -230,15 +228,3 @@ func (h *Handler) EditForm(ctx *context.Context) {
ctx.HTML(http.StatusOK, buf.String())
ctx.AddHeader(constant.PjaxUrlHeader, param.PreviousPath)
}

func (h *Handler) SetLanguage(ctx *context.Context) {
if len(ctx.PostForm()["language"]) == 0 {
return
}
if user, ok := ctx.UserValue["user"].(models.UserModel); ok {
config.SetUserConfig(config.UserConfig{
UserId: user.Id,
Language: ctx.PostForm()["language"][0],
})
}
}
15 changes: 15 additions & 0 deletions plugins/admin/modules/table/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,21 @@ func (s *SystemTable) GetNormalManagerTable(ctx *context.Context) (managerTable
FieldDisplay(func(value types.FieldModel) interface{} {
return ""
})
m := []types.FieldOption{}
m = append(m, types.FieldOption{
Text: language.CN,
Value: "zh",
}, types.FieldOption{
Text: language.EN,
Value: "en",
}, types.FieldOption{
Text: language.JP,
Value: "jp",
}, types.FieldOption{
Text: language.TC,
Value: "tc",
})
formList.AddField(lg("language"), "language", db.Varchar, form.SelectSingle).FieldOptions(m).FieldNotAllowAdd()

formList.SetTable("goadmin_users").SetTitle(lg("Managers")).SetDescription(lg("Managers"))
formList.SetUpdateFn(func(values form2.Values) error {
Expand Down

0 comments on commit 0f16580

Please sign in to comment.