mirror of https://github.com/mindoc-org/mindoc.git
update for init i18n
parent
0fb6fcb114
commit
f02ff935fe
|
@ -10,6 +10,8 @@ import (
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"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/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
"github.com/mindoc-org/mindoc/utils"
|
"github.com/mindoc-org/mindoc/utils"
|
||||||
|
@ -96,11 +98,16 @@ func ModifyPassword() {
|
||||||
func initialization() {
|
func initialization() {
|
||||||
|
|
||||||
err := models.NewOption().Init()
|
err := models.NewOption().Init()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
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")
|
member, err := models.NewMember().FindByFieldFirst("account", "admin")
|
||||||
if errors.Is(err, orm.ErrNoRows) {
|
if errors.Is(err, orm.ErrNoRows) {
|
||||||
|
|
||||||
|
@ -122,10 +129,10 @@ func initialization() {
|
||||||
book := models.NewBook()
|
book := models.NewBook()
|
||||||
|
|
||||||
book.MemberId = member.MemberId
|
book.MemberId = member.MemberId
|
||||||
book.BookName = "MinDoc演示项目"
|
book.BookName = i18n.Tr(lang, "init.default_proj_name") //"MinDoc演示项目"
|
||||||
book.Status = 0
|
book.Status = 0
|
||||||
book.ItemId = 1
|
book.ItemId = 1
|
||||||
book.Description = "这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。"
|
book.Description = i18n.Tr(lang, "init.default_proj_desc") //"这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。"
|
||||||
book.CommentCount = 0
|
book.CommentCount = 0
|
||||||
book.PrivatelyOwned = 0
|
book.PrivatelyOwned = 0
|
||||||
book.CommentStatus = "closed"
|
book.CommentStatus = "closed"
|
||||||
|
@ -137,7 +144,7 @@ func initialization() {
|
||||||
book.Editor = "markdown"
|
book.Editor = "markdown"
|
||||||
book.Theme = "default"
|
book.Theme = "default"
|
||||||
|
|
||||||
if err := book.Insert(); err != nil {
|
if err := book.Insert(lang); err != nil {
|
||||||
panic("初始化项目失败 -> " + err.Error())
|
panic("初始化项目失败 -> " + err.Error())
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -146,7 +153,7 @@ func initialization() {
|
||||||
|
|
||||||
if !models.NewItemsets().Exist(1) {
|
if !models.NewItemsets().Exist(1) {
|
||||||
item := models.NewItemsets()
|
item := models.NewItemsets()
|
||||||
item.ItemName = "默认项目空间"
|
item.ItemName = i18n.Tr(lang, "init.default_proj_space") //"默认项目空间"
|
||||||
item.MemberId = 1
|
item.MemberId = 1
|
||||||
if err := item.Save(); err != nil {
|
if err := item.Save(); err != nil {
|
||||||
panic("初始化项目空间失败 -> " + err.Error())
|
panic("初始化项目空间失败 -> " + err.Error())
|
||||||
|
|
|
@ -53,6 +53,12 @@ no = no
|
||||||
read = Read
|
read = Read
|
||||||
generate = Generate
|
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]
|
[message]
|
||||||
tips = Tips
|
tips = Tips
|
||||||
page_not_existed = The page does not exist
|
page_not_existed = The page does not exist
|
||||||
|
|
|
@ -53,6 +53,12 @@ no = 否
|
||||||
read = 阅读
|
read = 阅读
|
||||||
generate = 生成
|
generate = 生成
|
||||||
|
|
||||||
|
[init]
|
||||||
|
default_proj_name = MinDoc演示项目
|
||||||
|
default_proj_desc = 这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。
|
||||||
|
default_proj_space = 默认项目空间
|
||||||
|
blank_doc = 空白文档
|
||||||
|
|
||||||
[message]
|
[message]
|
||||||
tips = 友情提示
|
tips = 友情提示
|
||||||
page_not_existed = 页面不存在
|
page_not_existed = 页面不存在
|
||||||
|
|
|
@ -528,7 +528,7 @@ func (c *BookController) Create() {
|
||||||
book.Editor = "markdown"
|
book.Editor = "markdown"
|
||||||
book.Theme = "default"
|
book.Theme = "default"
|
||||||
|
|
||||||
if err := book.Insert(); err != nil {
|
if err := book.Insert(c.Lang); err != nil {
|
||||||
logs.Error("Insert => ", err)
|
logs.Error("Insert => ", err)
|
||||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ func NewBook() *Book {
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加一个项目
|
//添加一个项目
|
||||||
func (book *Book) Insert() error {
|
func (book *Book) Insert(lang string) error {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
// o.Begin()
|
// o.Begin()
|
||||||
book.BookName = utils.StripTags(book.BookName)
|
book.BookName = utils.StripTags(book.BookName)
|
||||||
|
@ -142,7 +142,7 @@ func (book *Book) Insert() error {
|
||||||
}
|
}
|
||||||
document := NewDocument()
|
document := NewDocument()
|
||||||
document.BookId = book.BookId
|
document.BookId = book.BookId
|
||||||
document.DocumentName = "空白文档"
|
document.DocumentName = i18n.Tr(lang, "init.blank_doc") //"空白文档"
|
||||||
document.MemberId = book.MemberId
|
document.MemberId = book.MemberId
|
||||||
err = document.InsertOrUpdate()
|
err = document.InsertOrUpdate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 29 KiB |
Loading…
Reference in New Issue