update for init i18n

pull/680/head
shiqstone 2021-04-21 22:00:03 +08:00
parent 0fb6fcb114
commit f02ff935fe
6 changed files with 27 additions and 8 deletions

View File

@ -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())

View File

@ -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

View File

@ -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 = 页面不存在

View File

@ -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"))
}

View File

@ -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 {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 29 KiB