diff --git a/conf/lang/en-us.ini b/conf/lang/en-us.ini index 0e474d85..e22781f8 100644 --- a/conf/lang/en-us.ini +++ b/conf/lang/en-us.ini @@ -37,6 +37,10 @@ js_lang = en remove = Remove operate = Operate confirm = Confirm +creator = Creator +administrator = Administrator +editor = Editor +observer = Observer [message] tips = Tips @@ -128,6 +132,8 @@ project_name_empty = Project name cannot be empty success = Success failed = Failed receive_account_empty = The recipient account cannot be empty +receive_account_not_exist = The recipient account not exist +receive_account_disabled = The recipient account disable cannot_preview = Cannot preview upload_failed = Upload failed upload_file_size_limit = The file must be less than 2MB @@ -157,6 +163,10 @@ get_doc_his_failed = Fail to get document history project_space_not_exist = Project space does not exist search_placeholder = input keyword please no_search_result = No search results! +user_exist_in_proj = The user already exists in the project +cannot_change_own_priv = Cannot change own permissions +cannot_delete_self = Cannot delete myself +cannot_handover_myself = Cannot handover to myself [blog] author = author @@ -242,7 +252,8 @@ search = Search expand = Unfold fold = Fold close = Close -doc_tool_copyright = Document is Published by MinDoc +doc_publish_by = Document is Published by +doc_publish = edit_doc = Edit Document backward = backward save = save @@ -336,6 +347,10 @@ bg_color = background color input_pwd = input password please read_pwd = read password commit = commit +ft_author = Author: +ft_last_editor = Last editor: +ft_create_time = Create time: +ft_update_time = Update time: [page] first = first diff --git a/conf/lang/zh-cn.ini b/conf/lang/zh-cn.ini index 8b924f30..e1e43802 100644 --- a/conf/lang/zh-cn.ini +++ b/conf/lang/zh-cn.ini @@ -37,6 +37,10 @@ js_lang = zh-CN remove = 移除 operate = 操作 confirm = 确定 +creator = 创始人 +administrator = 管理员 +editor = 编辑者 +observer = 观察者 [message] tips = 友情提示 @@ -128,6 +132,8 @@ project_name_empty = 项目名称不能为空 success = 成功 failed = 失败 receive_account_empty = 接受者账号不能为空 +receive_account_not_exist = 接受用户不存在 +receive_account_disabled = 接受用户已被禁用 cannot_preview = 不能预览 upload_failed = 上传失败 upload_file_size_limit = 文件必须小于2MB @@ -157,6 +163,10 @@ get_doc_his_failed = 获取历史失败 project_space_not_exist = 项目空间不存在 search_placeholder = 请输入搜索关键字 no_search_result = 暂无相关搜索结果! +user_exist_in_proj = 用户已存在该项目中 +cannot_change_own_priv = 不能变更自己的权限 +cannot_delete_self = 不能删除自己 +cannot_handover_myself = 不能转让给自己 [blog] author = 作者 @@ -242,7 +252,8 @@ search = 搜索 expand = 展开 fold = 收起 close = 关闭 -doc_tool_copyright = 本文档使用 MinDoc 发布 +doc_publish_by = 本文档使用 +doc_publish = 发布 edit_doc = 编辑文档 backward = 返回 save = 保存 @@ -336,6 +347,10 @@ bg_color = 背景颜色 input_pwd = 请输入密码 read_pwd = 浏览密码 commit = 提交 +ft_author = 作者: +ft_last_editor = 最后编辑: +ft_create_time = 创建时间: +ft_update_time = 更新时间: [page] first = 首页 diff --git a/controllers/BookController.go b/controllers/BookController.go index f4fbdfd6..195c8900 100644 --- a/controllers/BookController.go +++ b/controllers/BookController.go @@ -37,7 +37,7 @@ func (c *BookController) Index() { pageIndex, _ := c.GetInt("page", 1) - books, totalCount, err := models.NewBook().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId) + books, totalCount, err := models.NewBook().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId, c.Lang) if err != nil { logs.Error("BookController.Index => ", err) @@ -79,7 +79,7 @@ func (c *BookController) Dashboard() { c.Abort("404") } - book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId) + book, err := models.NewBookResult().SetLang(c.Lang).FindByIdentify(key, c.Member.MemberId) if err != nil { if err == models.ErrPermissionDenied { c.Abort("403") @@ -204,7 +204,7 @@ func (c *BookController) SaveBook() { book.AutoSave = 0 } if err := book.Update(); err != nil { - c.JsonResult(6006, "保存失败") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed")) } bookResult.BookName = bookName bookResult.Description = description @@ -221,7 +221,7 @@ func (c *BookController) PrivatelyOwned() { status := c.GetString("status") if status != "open" && status != "close" { - c.JsonResult(6003, "参数错误") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.param_error")) } state := 0 if status == "open" { @@ -238,13 +238,13 @@ func (c *BookController) PrivatelyOwned() { } //只有创始人才能变更私有状态 if bookResult.RoleId != conf.BookFounder { - c.JsonResult(6002, "权限不足") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.no_permission")) } book, err := models.NewBook().Find(bookResult.BookId) if err != nil { - c.JsonResult(6005, "项目不存在") + c.JsonResult(6005, i18n.Tr(c.Lang, "message.item_not_exist")) return } book.PrivatelyOwned = state @@ -253,7 +253,7 @@ func (c *BookController) PrivatelyOwned() { if err != nil { logs.Error("PrivatelyOwned => ", err) - c.JsonResult(6004, "保存失败") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.failed")) } logs.Info("用户 【", c.Member.Account, "]修改了项目权限 ->", state) c.JsonResult(0, "ok") @@ -265,19 +265,19 @@ func (c *BookController) Transfer() { account := c.GetString("account") if account == "" { - c.JsonResult(6004, "接受者账号不能为空") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.receive_account_empty")) } member, err := models.NewMember().FindByAccount(account) if err != nil { logs.Error("FindByAccount => ", err) - c.JsonResult(6005, "接受用户不存在") + c.JsonResult(6005, i18n.Tr(c.Lang, "message.receive_account_not_exist")) } if member.Status != 0 { - c.JsonResult(6006, "接受用户已被禁用") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.receive_account_disabled")) } if member.MemberId == c.Member.MemberId { - c.JsonResult(6007, "不能转让给自己") + c.JsonResult(6007, i18n.Tr(c.Lang, "message.cannot_handover_myself")) } bookResult, err := c.IsPermission() @@ -404,7 +404,7 @@ func (c *BookController) Users() { pageIndex, _ := c.GetInt("page", 1) if key == "" { - c.ShowErrorPage(404, "项目不存在或已删除") + c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist")) } book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId) @@ -421,7 +421,7 @@ func (c *BookController) Users() { } c.Data["Model"] = *book - members, totalCount, err := models.NewMemberRelationshipResult().FindForUsersByBookId(book.BookId, pageIndex, conf.PageSize) + members, totalCount, err := models.NewMemberRelationshipResult().FindForUsersByBookId(c.Lang, book.BookId, pageIndex, conf.PageSize) if totalCount > 0 { pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl()) @@ -553,7 +553,7 @@ func (c *BookController) Copy() { identify := strings.TrimSpace(c.GetString("identify", "")) if identify == "" { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } book := models.NewBook() err := book.Copy(identify) @@ -641,7 +641,7 @@ func (c *BookController) Import() { book.Editor = "markdown" book.Theme = "default" - go book.ImportBook(tempPath) + go book.ImportBook(tempPath, c.Lang) logs.Info("用户[", c.Member.Account, "]导入了项目 ->", book) @@ -657,10 +657,10 @@ func (c *BookController) Import() { // // if err != nil { // if err == models.ErrPermissionDenied { -// c.JsonResult(403, "权限不足") +// c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission")) // } // if err == orm.ErrNoRows { -// c.JsonResult(404, "项目不存在") +// c.JsonResult(404, i18n.Tr(c.Lang, "message.item_not_exist")) // } // logs.Error("生成阅读令牌失败 =>", err) // c.JsonResult(6002, err.Error()) @@ -668,7 +668,7 @@ func (c *BookController) Import() { // book := models.NewBook() // // if _, err := book.Find(bookResult.BookId); err != nil { -// c.JsonResult(6001, "项目不存在") +// c.JsonResult(6001, i18n.Tr(c.Lang, "message.item_not_exist")) // } // if action == "create" { // if bookResult.PrivatelyOwned == 0 { @@ -710,7 +710,7 @@ func (c *BookController) Delete() { err = models.NewBook().ThoroughDeleteBook(bookResult.BookId) if err == orm.ErrNoRows { - c.JsonResult(6002, "项目不存在") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist")) } if err != nil { logs.Error("删除项目 => ", err) @@ -741,22 +741,22 @@ func (c *BookController) Release() { if err != nil { if err == models.ErrPermissionDenied { - c.JsonResult(6001, "权限不足") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.no_permission")) } if err == orm.ErrNoRows { - c.JsonResult(6002, "项目不存在") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist")) } logs.Error(err) - c.JsonResult(6003, "未知错误") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.unknown_exception")) } if book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder && book.RoleId != conf.BookEditor { - c.JsonResult(6003, "权限不足") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.no_permission")) } bookId = book.BookId } - go models.NewBook().ReleaseContent(bookId) + go models.NewBook().ReleaseContent(bookId, c.Lang) - c.JsonResult(0, "发布任务已推送到任务队列,稍后将在后台执行。") + c.JsonResult(0, i18n.Tr(c.Lang, "message.publish_to_queue")) } //文档排序. @@ -772,7 +772,7 @@ func (c *BookController) SaveSort() { if c.Member.IsAdministrator() { book, err := models.NewBook().FindByFieldFirst("identify", identify) if err != nil || book == nil { - c.JsonResult(6001, "项目不存在") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.item_not_exist")) return } bookId = book.BookId @@ -784,7 +784,7 @@ func (c *BookController) SaveSort() { c.Abort("403") } if bookResult.RoleId == conf.BookObserver { - c.JsonResult(6002, "项目不存在或权限不足") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit")) } bookId = bookResult.BookId } @@ -808,7 +808,7 @@ func (c *BookController) SaveSort() { continue } if doc.BookId != bookId { - logs.Info("%s", "权限错误") + logs.Info("%s", i18n.Tr(c.Lang, "message.no_permission")) continue } sort, ok := item["sort"].(float64) @@ -848,15 +848,15 @@ func (c *BookController) Team() { pageIndex, _ := c.GetInt("page", 1) if key == "" { - c.ShowErrorPage(404, "项目不存在或已删除") + c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist")) } book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId) if err != nil || book == nil { if err == models.ErrPermissionDenied { - c.ShowErrorPage(403, "权限不足") + c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission")) } - c.ShowErrorPage(500, "系统错误") + c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error")) return } //如果不是创始人也不是管理员则不能操作 @@ -927,7 +927,7 @@ func (c *BookController) TeamDelete() { teamId, _ := c.GetInt("teamId") if teamId <= 0 { - c.JsonResult(5001, "参数错误") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.param_error")) } book, err := c.IsPermission() @@ -992,22 +992,22 @@ func (c *BookController) IsPermission() (*models.BookResult, error) { identify := c.GetString("identify") if identify == "" { - return nil, errors.New("参数错误") + return nil, errors.New(i18n.Tr(c.Lang, "message.param_error")) } book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId) if err != nil { if err == models.ErrPermissionDenied { - return book, errors.New("权限不足") + return book, errors.New(i18n.Tr(c.Lang, "message.no_permission")) } if err == orm.ErrNoRows { - return book, errors.New("项目不存在") + return book, errors.New(i18n.Tr(c.Lang, "message.item_not_exist")) } return book, err } if book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder { - return book, errors.New("权限不足") + return book, errors.New(i18n.Tr(c.Lang, "message.no_permission")) } return book, nil } diff --git a/controllers/BookMemberController.go b/controllers/BookMemberController.go index 782a4824..879ee03e 100644 --- a/controllers/BookMemberController.go +++ b/controllers/BookMemberController.go @@ -5,6 +5,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/models" ) @@ -20,7 +21,7 @@ func (c *BookMemberController) AddMember() { roleId, _ := c.GetInt("role_id", 3) logs.Info(account) if identify == "" || account <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } book, err := c.IsPermission() @@ -31,14 +32,14 @@ func (c *BookMemberController) AddMember() { member := models.NewMember() if _, err := member.Find(account); err != nil { - c.JsonResult(404, "用户不存在") + c.JsonResult(404, i18n.Tr(c.Lang, "message.user_not_existed")) } if member.Status == 1 { - c.JsonResult(6003, "用户已被禁用") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.user_disable")) } if _, err := models.NewRelationship().FindForRoleId(book.BookId, member.MemberId); err == nil { - c.JsonResult(6003, "用户已存在该项目中") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.user_exist_in_proj")) } relationship := models.NewRelationship() @@ -51,7 +52,7 @@ func (c *BookMemberController) AddMember() { memberRelationshipResult.RoleId = conf.BookRole(roleId) memberRelationshipResult.RelationshipId = relationship.RelationshipId memberRelationshipResult.BookId = book.BookId - memberRelationshipResult.ResolveRoleName() + memberRelationshipResult.ResolveRoleName(c.Lang) c.JsonResult(0, "ok", memberRelationshipResult) } @@ -65,33 +66,33 @@ func (c *BookMemberController) ChangeRole() { role, _ := c.GetInt("role_id", 0) if identify == "" || memberId <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } if memberId == c.Member.MemberId { - c.JsonResult(6006, "不能变更自己的权限") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.cannot_change_own_priv")) } book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId) if err != nil { if err == models.ErrPermissionDenied { - c.JsonResult(403, "权限不足") + c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission")) } if err == orm.ErrNoRows { - c.JsonResult(404, "项目不存在") + c.JsonResult(404, i18n.Tr(c.Lang, "message.item_not_exist")) } c.JsonResult(6002, err.Error()) } if book.RoleId != 0 && book.RoleId != 1 { - c.JsonResult(403, "权限不足") + c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission")) } member := models.NewMember() if _, err := member.Find(memberId); err != nil { - c.JsonResult(6003, "用户不存在") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.user_not_existed")) } if member.Status == 1 { - c.JsonResult(6004, "用户已被禁用") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.user_disable")) } relationship, err := models.NewRelationship().UpdateRoleId(book.BookId, memberId, conf.BookRole(role)) @@ -105,7 +106,7 @@ func (c *BookMemberController) ChangeRole() { memberRelationshipResult.RoleId = relationship.RoleId memberRelationshipResult.RelationshipId = relationship.RelationshipId memberRelationshipResult.BookId = book.BookId - memberRelationshipResult.ResolveRoleName() + memberRelationshipResult.ResolveRoleName(c.Lang) c.JsonResult(0, "ok", memberRelationshipResult) } @@ -116,25 +117,25 @@ func (c *BookMemberController) RemoveMember() { member_id, _ := c.GetInt("member_id", 0) if identify == "" || member_id <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } if member_id == c.Member.MemberId { - c.JsonResult(6006, "不能删除自己") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.cannot_delete_self")) } book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId) if err != nil { if err == models.ErrPermissionDenied { - c.JsonResult(403, "权限不足") + c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission")) } if err == orm.ErrNoRows { - c.JsonResult(404, "项目不存在") + c.JsonResult(404, i18n.Tr(c.Lang, "message.item_not_exist")) } c.JsonResult(6002, err.Error()) } //如果不是创始人也不是管理员则不能操作 if book.RoleId != conf.BookFounder && book.RoleId != conf.BookAdmin { - c.JsonResult(403, "权限不足") + c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission")) } err = models.NewRelationship().DeleteByBookIdAndMemberId(book.BookId, member_id) @@ -150,15 +151,15 @@ func (c *BookMemberController) IsPermission() (*models.BookResult, error) { if err != nil { if err == models.ErrPermissionDenied { - return book, errors.New("权限不足") + return book, errors.New(i18n.Tr(c.Lang, "message.no_permission")) } if err == orm.ErrNoRows { - return book, errors.New("项目不存在") + return book, errors.New(i18n.Tr(c.Lang, "message.item_not_exist")) } return book, err } if book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder { - return book, errors.New("权限不足") + return book, errors.New(i18n.Tr(c.Lang, "message.no_permission")) } return book, nil } diff --git a/controllers/DocumentController.go b/controllers/DocumentController.go index 158a5556..20266941 100644 --- a/controllers/DocumentController.go +++ b/controllers/DocumentController.go @@ -112,7 +112,6 @@ func (c *DocumentController) Read() { c.TplName = fmt.Sprintf("document/%s_read.tpl", bookResult.Theme) doc := models.NewDocument() - if docId, err := strconv.Atoi(id); err == nil { doc, err = doc.FromCacheById(docId) if err != nil || doc == nil { @@ -136,7 +135,7 @@ func (c *DocumentController) Read() { if doc.BookId != bookResult.BookId { c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.doc_not_exist")) } - + doc.Lang = c.Lang doc.Processor() attach, err := models.NewAttachment().FindListByDocumentId(doc.DocumentId) @@ -712,7 +711,6 @@ func (c *DocumentController) Content() { isCover := c.GetString("cover") doc, err := models.NewDocument().Find(docId) - if err != nil || doc == nil { c.JsonResult(6003, i18n.Tr(c.Lang, "message.read_file_error")) return @@ -768,6 +766,7 @@ func (c *DocumentController) Content() { //如果启用了自动发布 if autoRelease { go func() { + doc.Lang = c.Lang err := doc.ReleaseContent() if err == nil { logs.Informational(i18n.Tr(c.Lang, "message.doc_auto_published")+"-> document_id=%d;document_name=%s", doc.DocumentId, doc.DocumentName) diff --git a/controllers/ManagerController.go b/controllers/ManagerController.go index dc7bd4b4..a11f9689 100644 --- a/controllers/ManagerController.go +++ b/controllers/ManagerController.go @@ -192,6 +192,7 @@ func (c *ManagerController) ChangeMemberRole() { if err := member.Update(); err != nil { c.JsonResult(6003, "用户权限设置失败") } + member.Lang = c.Lang member.ResolveRoleName() c.JsonResult(0, "ok", member) } diff --git a/models/BookModel.go b/models/BookModel.go index 5d3662bf..33378934 100644 --- a/models/BookModel.go +++ b/models/BookModel.go @@ -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 } diff --git a/models/BookResult.go b/models/BookResult.go index ce628e1c..cc6818ba 100644 --- a/models/BookResult.go +++ b/models/BookResult.go @@ -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() diff --git a/models/DocumentModel.go b/models/DocumentModel.go index 356c8a8f..c0b4a52b 100644 --- a/models/DocumentModel.go +++ b/models/DocumentModel.go @@ -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("
附件