From 0fb6fcb1148ee8a25c2e2196107af6368d5efd33 Mon Sep 17 00:00:00 2001 From: shiqstone Date: Wed, 21 Apr 2021 20:44:19 +0800 Subject: [PATCH] fix bug for i18n and beego v2 --- commands/daemon/daemon.go | 1 - conf/lang/en-us.ini | 5 +++-- conf/lang/zh-cn.ini | 3 ++- controllers/BaseController.go | 8 +++----- go.sum | 9 +++++++++ models/Blog.go | 1 - models/DocumentModel.go | 3 +-- utils/pagination/pagination.go | 7 ++++--- views/blog/manage_setting.tpl | 4 ++-- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/commands/daemon/daemon.go b/commands/daemon/daemon.go index 889c3f1a..afed74c3 100644 --- a/commands/daemon/daemon.go +++ b/commands/daemon/daemon.go @@ -2,7 +2,6 @@ package daemon import ( "fmt" - "github.com/astaxie/beego/logs" "os" "path/filepath" diff --git a/conf/lang/en-us.ini b/conf/lang/en-us.ini index 3f700021..262a3c56 100644 --- a/conf/lang/en-us.ini +++ b/conf/lang/en-us.ini @@ -327,8 +327,8 @@ search = Search expand = Unfold fold = Fold close = Close -doc_publish_by = Document is Published by -doc_publish = +doc_publish_by = Document is Published by +doc_publish = edit_doc = Edit Document backward = backward save = save @@ -426,6 +426,7 @@ ft_author = Author: ft_last_editor = Last editor: ft_create_time = Create time: ft_update_time = Update time: +view_count = Number of views [project] prj_space_list = Project Space List diff --git a/conf/lang/zh-cn.ini b/conf/lang/zh-cn.ini index 9f16be0c..5c2f6a66 100644 --- a/conf/lang/zh-cn.ini +++ b/conf/lang/zh-cn.ini @@ -327,7 +327,7 @@ search = 搜索 expand = 展开 fold = 收起 close = 关闭 -doc_publish_by = 本文档使用 +doc_publish_by = 本文档使用 doc_publish = 发布 edit_doc = 编辑文档 backward = 返回 @@ -426,6 +426,7 @@ ft_author = 作者: ft_last_editor = 最后编辑: ft_create_time = 创建时间: ft_update_time = 更新时间: +view_amount = 阅读次数 [project] prj_space_list = 项目空间列表 diff --git a/controllers/BaseController.go b/controllers/BaseController.go index 2d282de4..7e2a5571 100644 --- a/controllers/BaseController.go +++ b/controllers/BaseController.go @@ -7,15 +7,13 @@ import ( "strings" "time" - "github.com/astaxie/beego/logs" - "github.com/beego/i18n" - "html/template" "io/ioutil" "path/filepath" "github.com/beego/beego/v2/core/logs" "github.com/beego/beego/v2/server/web" + "github.com/beego/i18n" "github.com/mindoc-org/mindoc/conf" "github.com/mindoc-org/mindoc/models" "github.com/mindoc-org/mindoc/utils" @@ -211,14 +209,14 @@ func (c *BaseController) CheckErrorResult(code int, err error) { func (c *BaseController) SetLang() { hasCookie := false - lang := c.Input().Get("lang") + lang := c.GetString("lang") if len(lang) == 0 { lang = c.Ctx.GetCookie("lang") hasCookie = true } if len(lang) == 0 || !i18n.IsExist(lang) { - lang = beego.AppConfig.String("default_lang") + lang, _ = web.AppConfig.String("default_lang") } if !hasCookie { c.Ctx.SetCookie("lang", lang, 1<<31-1, "/") diff --git a/go.sum b/go.sum index c6bcf5e2..e74efd15 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= @@ -105,6 +107,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kardianos/service v1.1.0 h1:QV2SiEeWK42P0aEmGcsAgjApw/lRxkwopvT+Gu6t1/0= github.com/kardianos/service v1.1.0/go.mod h1:RrJI2xn5vve/r32U5suTbeaSGoMU6GbNPoj36CVYcHc= @@ -180,6 +184,10 @@ github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKz github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -258,6 +266,7 @@ golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= diff --git a/models/Blog.go b/models/Blog.go index e2ebc328..7e8e5d19 100644 --- a/models/Blog.go +++ b/models/Blog.go @@ -3,7 +3,6 @@ package models import ( "bytes" "fmt" - "github.com/astaxie/beego/logs" "strings" "time" diff --git a/models/DocumentModel.go b/models/DocumentModel.go index bd709f37..f0ed549c 100644 --- a/models/DocumentModel.go +++ b/models/DocumentModel.go @@ -3,7 +3,6 @@ package models import ( "time" - "github.com/astaxie/beego/logs" "github.com/beego/i18n" "fmt" @@ -340,7 +339,7 @@ func (item *Document) Processor() *Document { selector.First().AppendHtml(release) } } - cdnimg,_ := web.AppConfig.String("cdnimg") + cdnimg, _ := web.AppConfig.String("cdnimg") docQuery.Find("img").Each(func(i int, selection *goquery.Selection) { diff --git a/utils/pagination/pagination.go b/utils/pagination/pagination.go index df25d91a..6a3067c8 100644 --- a/utils/pagination/pagination.go +++ b/utils/pagination/pagination.go @@ -2,14 +2,15 @@ package pagination import ( "fmt" - "github.com/astaxie/beego" - "github.com/beego/i18n" "html/template" "math" "net/http" "net/url" "strconv" "strings" + + "github.com/beego/beego/v2/server/web" + "github.com/beego/i18n" ) //Pagination 分页器 @@ -117,7 +118,7 @@ func (p *Pagination) pageURL(page string) string { } func (p *Pagination) getLang() string { - lang := beego.AppConfig.String("default_lang") + lang, _ := web.AppConfig.String("default_lang") ulang := p.Request.FormValue("lang") if len(ulang) == 0 { clang, err := p.Request.Cookie("lang") diff --git a/views/blog/manage_setting.tpl b/views/blog/manage_setting.tpl index 8b29ef37..399190cd 100644 --- a/views/blog/manage_setting.tpl +++ b/views/blog/manage_setting.tpl @@ -25,8 +25,8 @@