diff --git a/config/config.go b/config/config.go index 98d571c..5c6921d 100644 --- a/config/config.go +++ b/config/config.go @@ -15,6 +15,7 @@ const Dir = "config/" const AccountConf = Dir + "account.json" const MysqlConf = Dir + "mysql.json" const MailConf = Dir + "mail.json" +const LangConf=Dir+"language.json" type Mysql struct{ Server string Port string diff --git a/config/language.go b/config/language.go index 1f3a11e..6bf977a 100644 --- a/config/language.go +++ b/config/language.go @@ -1,11 +1,16 @@ package config + type Language struct { WebCopyRight string MainIntro string - IndexSubIntro,IndexVisitors,IndexAgent,IndexDocument string + Send string + Notice string + IndexSubIntro,IndexVisitors,IndexAgent,IndexDocument,IndexOnlineChat string } + func CreateLanguage(lang string)*Language{ var language *Language + if lang=="en"{ language=&Language{ WebCopyRight: "TaoShihan", @@ -14,6 +19,9 @@ func CreateLanguage(lang string)*Language{ IndexDocument:"API Documents", IndexVisitors:"Visitors Here", IndexAgent:"Agents Here", + IndexOnlineChat:"Let’s chat. - We're online", + Send:"Send", + Notice:"Hello and welcome to go-fly - how can we help?", } } if lang=="cn"{ @@ -24,6 +32,9 @@ func CreateLanguage(lang string)*Language{ IndexVisitors:"访客入口", IndexAgent:"客服入口", IndexDocument:"接口文档", + IndexOnlineChat:"在线咨询", + Send:"发送", + Notice:"欢迎您访问go-fly!有什么我能帮助您的?", } } return language diff --git a/config/language.json b/config/language.json new file mode 100644 index 0000000..e40e6e5 --- /dev/null +++ b/config/language.json @@ -0,0 +1,20 @@ +{ + "En":{ + "WebCopyRight": "TaoShihan", + "MainIntro": "Simple and Powerful Go language online customer chat system", + "IndexSubIntro": "GO-FLY, a Vue 2.0-based online customer service instant messaging system for PHP engineers and Golang engineers", + "IndexDocument":"API Documents", + "IndexVisitors":"Visitors Here", + "IndexAgent":"Agents Here", + "IndexOnlineChat":"Let’s chat. - We're online" + }, + "Cn":{ + "WebCopyRight": "陶士涵的菜地版权所有", + "MainIntro":"极简强大的Go语言在线客服系统", + "IndexSubIntro":"GO-FLY,一套为PHP工程师、Golang工程师准备的基于 Vue 2.0的在线客服即时通讯系统", + "IndexVisitors":"访客入口", + "IndexAgent":"客服入口", + "IndexDocument":"接口文档", + "IndexOnlineChat":"在线咨询" + } +} diff --git a/controller/notice.go b/controller/notice.go index d8e8369..e0010d1 100644 --- a/controller/notice.go +++ b/controller/notice.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" + "github.com/taoshihan1991/imaptool/config" "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tools" "log" @@ -12,12 +13,15 @@ import ( ) func GetNotice(c *gin.Context) { kefuId:=c.Query("kefu_id") + lang,_:=c.Get("lang") + language:=config.CreateLanguage(lang.(string)) + user:=models.FindUser(kefuId) info:=make(map[string]interface{}) info["nickname"]=user.Nickname info["avator"]=user.Avator info["name"]=user.Name - info["content"]="欢迎您!有什么我能帮助您的?" + info["content"]=language.Notice info["time"]=time.Now().Format("2006-01-02 15:04:05") c.JSON(200, gin.H{ "code": 200, diff --git a/main.go b/main.go index ba8f55a..d82a8d9 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ func main() { //登陆界面 engine.GET("/login", tmpl.PageLogin) //咨询界面 - engine.GET("/chat_page", tmpl.PageChat) + engine.GET("/chat_page",middleware.SetLanguage, tmpl.PageChat) //登陆验证 engine.POST("/check", controller.LoginCheckPass) //框架界面 @@ -82,7 +82,7 @@ func main() { engine.GET("/setting_kefu_list",tmpl.PageKefuList) //前台接口 - engine.GET("/notice", controller.GetNotice) + engine.GET("/notice",middleware.SetLanguage, controller.GetNotice) //前台引入js接口 engine.GET("/webjs", tmpl.PageWebJs) //前台引入css接口 diff --git a/middleware/language.go b/middleware/language.go new file mode 100644 index 0000000..12f3898 --- /dev/null +++ b/middleware/language.go @@ -0,0 +1,14 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" +) + +func SetLanguage(c *gin.Context){ + lang := c.Query("lang") + if lang == "" ||lang!="cn"{ + lang = "en" + } + c.Set("lang",lang) +} + diff --git a/static/html/chat_page.html b/static/html/chat_page.html index 744ec88..9055d57 100644 --- a/static/html/chat_page.html +++ b/static/html/chat_page.html @@ -109,7 +109,7 @@
- 发送 + {{.SendBtn}}
@@ -294,7 +294,7 @@ //获取自动欢迎语句 getNotice : function (){ let _this=this; - $.get("/notice?kefu_id="+guest.to_id,function(res) { + $.get("/notice?kefu_id="+guest.to_id+"&lang={{.Lang}}",function(res) { console.log(res); if (res.result != null) { let msg = res.result; diff --git a/static/html/index.html b/static/html/index.html index 6e7af7b..a2e92a3 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -115,7 +115,11 @@

{{.SubIntro}}

+ {{if eq .Lang "en"}} + + {{else}} + {{end}}