refactor and update i18n, to be continue
This commit is contained in:
shiqstone
2021-04-12 21:12:26 +08:00
parent a5682f1308
commit 6eb26fcb23
12 changed files with 140 additions and 93 deletions

View File

@@ -18,6 +18,7 @@ import (
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/beego/i18n"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/utils"
"github.com/mindoc-org/mindoc/utils/cryptil"
@@ -323,7 +324,7 @@ func (book *Book) FindByIdentify(identify string, cols ...string) (*Book, error)
}
//分页查询指定用户的项目
func (book *Book) FindToPager(pageIndex, pageSize, memberId int) (books []*BookResult, totalCount int, err error) {
func (book *Book) FindToPager(pageIndex, pageSize, memberId int, lang string) (books []*BookResult, totalCount int, err error) {
o := orm.NewOrm()
@@ -391,13 +392,13 @@ ORDER BY book.order_index, book.book_id DESC limit ?,?`
books[index].LastModifyText = text.Account + " 于 " + text.ModifyTime.Format("2006-01-02 15:04:05")
}
if book.RoleId == 0 {
book.RoleName = "创始人"
book.RoleName = i18n.Tr(lang, "common.creator")
} else if book.RoleId == 1 {
book.RoleName = "管理员"
book.RoleName = i18n.Tr(lang, "common.administrator")
} else if book.RoleId == 2 {
book.RoleName = "编辑者"
book.RoleName = i18n.Tr(lang, "common.editor")
} else if book.RoleId == 3 {
book.RoleName = "观察者"
book.RoleName = i18n.Tr(lang, "common.observer")
}
}
}
@@ -585,7 +586,7 @@ WHERE (relationship_id > 0 OR book.privately_owned = 0 or team.team_member_id >
}
// ReleaseContent 批量发布文档
func (book *Book) ReleaseContent(bookId int) {
func (book *Book) ReleaseContent(bookId int, lang string) {
releaseQueue <- bookId
once.Do(func() {
go func() {
@@ -606,6 +607,7 @@ func (book *Book) ReleaseContent(bookId int) {
}
for _, item := range docs {
item.BookId = bookId
item.Lang = lang
_ = item.ReleaseContent()
}
@@ -633,7 +635,7 @@ func (book *Book) ResetDocumentNumber(bookId int) {
}
//导入项目
func (book *Book) ImportBook(zipPath string) error {
func (book *Book) ImportBook(zipPath string, lang string) error {
if !filetil.FileExists(zipPath) {
return errors.New("文件不存在 => " + zipPath)
}
@@ -926,7 +928,7 @@ func (book *Book) ImportBook(zipPath string) error {
book.Description = "【项目导入存在错误:" + err.Error() + "】"
}
logs.Info("项目导入完毕 => ", book.BookName)
book.ReleaseContent(book.BookId)
book.ReleaseContent(book.BookId, lang)
return err
}

View File

@@ -17,6 +17,7 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/beego/i18n"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/converter"
"github.com/mindoc-org/mindoc/utils/cryptil"
@@ -70,6 +71,7 @@ type BookResult struct {
IsDisplayComment bool `json:"is_display_comment"`
IsDownload bool `json:"is_download"`
AutoSave bool `json:"auto_save"`
Lang string
}
func NewBookResult() *BookResult {
@@ -85,6 +87,11 @@ func (m *BookResult) String() string {
return string(ret)
}
func (m *BookResult) SetLang(lang string) *BookResult {
m.Lang = lang
return m
}
// 根据项目标识查询项目以及指定用户权限的信息.
func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult, error) {
if identify == "" || memberId <= 0 {
@@ -131,13 +138,13 @@ func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult,
}
if m.RoleId == conf.BookFounder {
m.RoleName = "创始人"
m.RoleName = i18n.Tr(m.Lang, "common.creator")
} else if m.RoleId == conf.BookAdmin {
m.RoleName = "管理员"
m.RoleName = i18n.Tr(m.Lang, "common.administrator")
} else if m.RoleId == conf.BookEditor {
m.RoleName = "编辑者"
m.RoleName = i18n.Tr(m.Lang, "common.editor")
} else if m.RoleId == conf.BookObserver {
m.RoleName = "观察者"
m.RoleName = i18n.Tr(m.Lang, "common.observer")
}
doc := NewDocument()

View File

@@ -1,9 +1,11 @@
package models
import (
"github.com/astaxie/beego/logs"
"time"
"github.com/astaxie/beego/logs"
"github.com/beego/i18n"
"fmt"
"strconv"
@@ -43,6 +45,8 @@ type Document struct {
//是否展开子目录0 否/1 是 /2 空间节点,单击时展开下一级
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
AttachList []*Attachment `orm:"-" json:"attach"`
//i18n
Lang string `orm:"-"`
}
// 多字段唯一键
@@ -275,7 +279,7 @@ func (item *Document) Processor() *Document {
//处理附件
attachList, err := NewAttachment().FindListByDocumentId(item.DocumentId)
if err == nil && len(attachList) > 0 {
content := bytes.NewBufferString("<div class=\"attach-list\"><strong>附件</strong><ul>")
content := bytes.NewBufferString("<div class=\"attach-list\"><strong>" + i18n.Tr(item.Lang, "doc.attachment") + "</strong><ul>")
for _, attach := range attachList {
if strings.HasPrefix(attach.HttpPath, "/") {
attach.HttpPath = strings.TrimSuffix(conf.BaseUrl, "/") + attach.HttpPath
@@ -305,7 +309,7 @@ func (item *Document) Processor() *Document {
docCreator, err := NewMember().Find(item.MemberId, "real_name", "account")
release := "<div class=\"wiki-bottom\">"
release += "作者:"
release += i18n.Tr(item.Lang, "doc.ft_author")
if err == nil && docCreator != nil {
if docCreator.RealName != "" {
release += docCreator.RealName
@@ -313,19 +317,19 @@ func (item *Document) Processor() *Document {
release += docCreator.Account
}
}
release += " &nbsp;创建时间:" + item.CreateTime.Local().Format("2006-01-02 15:04") + "<br>"
release += " &nbsp;" + i18n.Tr(item.Lang, "doc.ft_create_time") + item.CreateTime.Local().Format("2006-01-02 15:04") + "<br>"
if item.ModifyAt > 0 {
docModify, err := NewMember().Find(item.ModifyAt, "real_name", "account")
if err == nil {
if docModify.RealName != "" {
release += "最后编辑:" + docModify.RealName
release += i18n.Tr(item.Lang, "doc.ft_last_editor") + docModify.RealName
} else {
release += "最后编辑:" + docModify.Account
release += i18n.Tr(item.Lang, "doc.ft_last_editor") + docModify.Account
}
}
}
release += " &nbsp;更新时间:" + item.ModifyTime.Local().Format("2006-01-02 15:04") + "<br>"
release += " &nbsp;" + i18n.Tr(item.Lang, "doc.ft_update_time") + item.ModifyTime.Local().Format("2006-01-02 15:04") + "<br>"
release += "</div>"
if selector := docQuery.Find("div.markdown-article").First(); selector.Size() > 0 {

View File

@@ -22,6 +22,7 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/beego/i18n"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/utils"
)
@@ -44,6 +45,8 @@ type Member struct {
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
CreateAt int `orm:"type(int);column(create_at)" json:"create_at"`
LastLoginTime time.Time `orm:"type(datetime);column(last_login_time);null" json:"last_login_time"`
//i18n
Lang string `orm:"-"`
}
// TableName 获取对应数据库表名.
@@ -321,11 +324,11 @@ func (m *Member) Find(id int, cols ...string) (*Member, error) {
func (m *Member) ResolveRoleName() {
if m.Role == conf.MemberSuperRole {
m.RoleName = "超级管理员"
m.RoleName = i18n.Tr(m.Lang, "common.administrator")
} else if m.Role == conf.MemberAdminRole {
m.RoleName = "管理员"
m.RoleName = i18n.Tr(m.Lang, "common.editor")
} else if m.Role == conf.MemberGeneralRole {
m.RoleName = "普通用户"
m.RoleName = i18n.Tr(m.Lang, "common.obverser")
}
}

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/astaxie/beego/orm"
"github.com/beego/i18n"
"github.com/mindoc-org/mindoc/conf"
)
@@ -54,19 +55,19 @@ func (m *MemberRelationshipResult) FromMember(member *Member) *MemberRelationshi
return m
}
func (m *MemberRelationshipResult) ResolveRoleName() *MemberRelationshipResult {
func (m *MemberRelationshipResult) ResolveRoleName(lang string) *MemberRelationshipResult {
if m.RoleId == conf.BookAdmin {
m.RoleName = "管理者"
m.RoleName = i18n.Tr(lang, "common.administrator")
} else if m.RoleId == conf.BookEditor {
m.RoleName = "编辑者"
m.RoleName = i18n.Tr(lang, "common.editor")
} else if m.RoleId == conf.BookObserver {
m.RoleName = "观察者"
m.RoleName = i18n.Tr(lang, "common.obverser")
}
return m
}
// 根据项目ID查询用户
func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
func (m *MemberRelationshipResult) FindForUsersByBookId(lang string, bookId, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
o := orm.NewOrm()
var members []*MemberRelationshipResult
@@ -92,7 +93,7 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageS
}
for _, item := range members {
item.ResolveRoleName()
item.ResolveRoleName(lang)
}
return members, total_count, nil
}
@@ -118,8 +119,7 @@ func (m *MemberRelationshipResult) FindNotJoinUsersByAccountOrRealName(bookId, l
var members []*Member
_, err := o.Raw(sql, bookId, keyWord,keyWord, limit).QueryRows(&members)
_, err := o.Raw(sql, bookId, keyWord, keyWord, limit).QueryRows(&members)
return members, err
}