diff --git a/commands/install.go b/commands/install.go index 2b53694c..6cabc387 100644 --- a/commands/install.go +++ b/commands/install.go @@ -10,6 +10,8 @@ import ( "github.com/beego/beego/v2/client/orm" "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" @@ -96,11 +98,16 @@ func ModifyPassword() { func initialization() { err := models.NewOption().Init() - if err != nil { panic(err.Error()) } + lang, _ := web.AppConfig.String("default_lang") + err = i18n.SetMessage(lang, "conf/lang/"+lang+".ini") + if err != nil { + panic(fmt.Errorf("initialize locale error: %s", err)) + } + member, err := models.NewMember().FindByFieldFirst("account", "admin") if errors.Is(err, orm.ErrNoRows) { @@ -122,10 +129,10 @@ func initialization() { book := models.NewBook() book.MemberId = member.MemberId - book.BookName = "MinDoc演示项目" + book.BookName = i18n.Tr(lang, "init.default_proj_name") //"MinDoc演示项目" book.Status = 0 book.ItemId = 1 - book.Description = "这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。" + book.Description = i18n.Tr(lang, "init.default_proj_desc") //"这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。" book.CommentCount = 0 book.PrivatelyOwned = 0 book.CommentStatus = "closed" @@ -137,7 +144,7 @@ func initialization() { book.Editor = "markdown" book.Theme = "default" - if err := book.Insert(); err != nil { + if err := book.Insert(lang); err != nil { panic("初始化项目失败 -> " + err.Error()) } } else if err != nil { @@ -146,7 +153,7 @@ func initialization() { if !models.NewItemsets().Exist(1) { item := models.NewItemsets() - item.ItemName = "默认项目空间" + item.ItemName = i18n.Tr(lang, "init.default_proj_space") //"默认项目空间" item.MemberId = 1 if err := item.Save(); err != nil { panic("初始化项目空间失败 -> " + err.Error()) diff --git a/conf/lang/en-us.ini b/conf/lang/en-us.ini index 262a3c56..b03bd961 100644 --- a/conf/lang/en-us.ini +++ b/conf/lang/en-us.ini @@ -53,6 +53,12 @@ no = no read = Read generate = Generate +[init] +default_proj_name = MinDoc Demo Project +default_proj_desc = This is a MinDoc demo project, which is automatically created when the system is initialized. +default_proj_space = Default Project Space +blank_doc = Blank document + [message] tips = Tips page_not_existed = The page does not exist diff --git a/conf/lang/zh-cn.ini b/conf/lang/zh-cn.ini index 5c2f6a66..adf045de 100644 --- a/conf/lang/zh-cn.ini +++ b/conf/lang/zh-cn.ini @@ -53,6 +53,12 @@ no = 否 read = 阅读 generate = 生成 +[init] +default_proj_name = MinDoc演示项目 +default_proj_desc = 这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。 +default_proj_space = 默认项目空间 +blank_doc = 空白文档 + [message] tips = 友情提示 page_not_existed = 页面不存在 diff --git a/controllers/BookController.go b/controllers/BookController.go index 091a032d..669d3a29 100644 --- a/controllers/BookController.go +++ b/controllers/BookController.go @@ -528,7 +528,7 @@ func (c *BookController) Create() { book.Editor = "markdown" book.Theme = "default" - if err := book.Insert(); err != nil { + if err := book.Insert(c.Lang); err != nil { logs.Error("Insert => ", err) c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed")) } diff --git a/models/BookModel.go b/models/BookModel.go index c24c715b..d78f6ca2 100644 --- a/models/BookModel.go +++ b/models/BookModel.go @@ -116,7 +116,7 @@ func NewBook() *Book { } //添加一个项目 -func (book *Book) Insert() error { +func (book *Book) Insert(lang string) error { o := orm.NewOrm() // o.Begin() book.BookName = utils.StripTags(book.BookName) @@ -142,7 +142,7 @@ func (book *Book) Insert() error { } document := NewDocument() document.BookId = book.BookId - document.DocumentName = "空白文档" + document.DocumentName = i18n.Tr(lang, "init.blank_doc") //"空白文档" document.MemberId = book.MemberId err = document.InsertOrUpdate() if err != nil { diff --git a/static/images/book.jpg b/static/images/book.jpg index 4a29c860..79f6279e 100644 Binary files a/static/images/book.jpg and b/static/images/book.jpg differ