From 0f1658078d17531547de7c1f0de25f7dccef53cd Mon Sep 17 00:00:00 2001 From: laijinhang <761774955@qq.com> Date: Sat, 14 Mar 2020 17:33:06 +0800 Subject: [PATCH] switch language on the front end --- examples/gin/main.go | 2 +- go.mod | 2 ++ go.sum | 6 ++++++ modules/language/cn.go | 2 ++ modules/language/en.go | 1 + modules/language/jp.go | 6 ++++++ modules/language/tc.go | 1 + plugins/admin/controller/edit.go | 16 +--------------- plugins/admin/modules/table/generators.go | 15 +++++++++++++++ 9 files changed, 35 insertions(+), 16 deletions(-) diff --git a/examples/gin/main.go b/examples/gin/main.go index 8a332b4d4..4aed5fdfc 100644 --- a/examples/gin/main.go +++ b/examples/gin/main.go @@ -37,7 +37,7 @@ func main() { Port: "3306", User: "root", Pwd: "root", - Name: "godmin", + Name: "goadmin", MaxIdleCon: 50, MaxOpenCon: 150, Driver: config.DriverMysql, diff --git a/go.mod b/go.mod index 28fc3a3eb..020dda354 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ae5a86449..10e267328 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/modules/language/cn.go b/modules/language/cn.go index 708c96f4d..62308a43a 100644 --- a/modules/language/cn.go +++ b/modules/language/cn.go @@ -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": "语言", } diff --git a/modules/language/en.go b/modules/language/en.go index 341f62b98..7286f1ecb 100644 --- a/modules/language/en.go +++ b/modules/language/en.go @@ -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", } diff --git a/modules/language/jp.go b/modules/language/jp.go index f7164402c..70d916bc9 100644 --- a/modules/language/jp.go +++ b/modules/language/jp.go @@ -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": "言語", } diff --git a/modules/language/tc.go b/modules/language/tc.go index af38a1bde..9514fbd9b 100644 --- a/modules/language/tc.go +++ b/modules/language/tc.go @@ -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": "語言", } diff --git a/plugins/admin/controller/edit.go b/plugins/admin/controller/edit.go index ef5b11d47..8f9630053 100644 --- a/plugins/admin/controller/edit.go +++ b/plugins/admin/controller/edit.go @@ -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" @@ -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" @@ -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], - }) - } -} diff --git a/plugins/admin/modules/table/generators.go b/plugins/admin/modules/table/generators.go index 40b76ea45..4de15c7d9 100644 --- a/plugins/admin/modules/table/generators.go +++ b/plugins/admin/modules/table/generators.go @@ -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 {