From 581d902cd88408f66e4146784103b301301b7078 Mon Sep 17 00:00:00 2001 From: Ben Stone Date: Wed, 31 Mar 2021 17:13:05 +0800 Subject: [PATCH] refactor and update i18n, to be continue --- conf/lang/en-us.ini | 6 ++ conf/lang/zh-cn.ini | 56 +++++++++++- utils/pagination/pagination.go | 39 ++++++--- views/book/index.tpl | 154 ++++++++++++++++----------------- 4 files changed, 167 insertions(+), 88 deletions(-) diff --git a/conf/lang/en-us.ini b/conf/lang/en-us.ini index 23a5df21..597c6640 100644 --- a/conf/lang/en-us.ini +++ b/conf/lang/en-us.ini @@ -116,3 +116,9 @@ project_id = Project ID project_desc = Project description public = Public private = Private + +[page] +first = first +last = last +prev = prev +next = next \ No newline at end of file diff --git a/conf/lang/zh-cn.ini b/conf/lang/zh-cn.ini index 31c15257..4e1bdc42 100644 --- a/conf/lang/zh-cn.ini +++ b/conf/lang/zh-cn.ini @@ -25,6 +25,11 @@ account_recovery = 找回密码 new_password = 新密码 confirm_password = 确认密码 new_account = 用户注册 +setting = 设置 +save = 保存 +cancel = 取消 +create = 创建 +confirm_delete = 确定删除 [message] keyword_placeholder = 请输入关键词... @@ -65,6 +70,55 @@ failed_obtain_user_info = 获取身份信息失败 dingtalk_auto_login_not_enable = 未开启钉钉自动登录功能 failed_auto_login = 自动登录失败 no_project = 暂无项目 +item_not_exist = 项目不存在或已删除 +doc_not_exist = 文档不存在或已删除 +unknown_exception = 未知异常 +no_data = 暂无数据 +project_must_belong_space = 每个项目必须归属一个项目空间,超级管理员可在后台管理和维护 +project_title_placeholder = 项目标题(不超过100字) +project_title_tips = 项目标题不能超过100字符 +project_id_placeholder = 项目唯一标识(不超过50字) +project_id_tips = 文档标识只能包含小写字母、数字,以及“-”、“.”和“_”符号. +project_desc_placeholder = 描述信息不超过500个字符 +project_public_desc = (任何人都可以访问) +project_private_desc = (只有参与者或使用令牌才能访问) +project_cover_desc = 项目图片可在项目设置中修改 +confirm_delete_project = 确定删除项目吗? +warning_delete_project = 删除项目后将无法找回。 +project_space_empty = 请选择项目空间 +project_title_empty = 项目标题不能为空 +project_id_empty = 项目标识不能为空 +project_id_length = 项目标识必须小于50字符 +import_file_empty = 请选择需要上传的文件 +file_type_placeholder = 请选择Zip文件 [blog] -author = 作者 \ No newline at end of file +author = 作者 +project_list = 项目列表 +add_project = 添加项目 +import_project = 导入项目 +delete_project = 删除项目 +project_summary = 项目概要 +read = 阅读 +edit = 编辑 +delete = 删除 +copy = 复制 +view = 查看文档 +edit_doc = 编辑文档 +default_cover = 默认封面 +create_time = 创建时间 +creator = 创建者 +doc_amount = 文档数量 +project_role = 项目角色 +last_edit = 最后编辑 +project_title = 项目标题 +project_id = 项目标识 +project_desc = 项目描述 +public = 公开 +private = 私有 + +[page] +first = 首页 +last = 末页 +prev = 上一页 +next = 下一页 \ No newline at end of file diff --git a/utils/pagination/pagination.go b/utils/pagination/pagination.go index f6dcec43..df25d91a 100644 --- a/utils/pagination/pagination.go +++ b/utils/pagination/pagination.go @@ -2,12 +2,14 @@ package pagination import ( "fmt" + "github.com/astaxie/beego" + "github.com/beego/i18n" + "html/template" "math" "net/http" "net/url" "strconv" "strings" - "html/template" ) //Pagination 分页器 @@ -19,7 +21,7 @@ type Pagination struct { } //NewPagination 新建分页器 -func NewPagination(req *http.Request, total int, pernum int,baseUrl string) *Pagination { +func NewPagination(req *http.Request, total int, pernum int, baseUrl string) *Pagination { return &Pagination{ Request: req, Total: total, @@ -49,6 +51,8 @@ func (p *Pagination) Pages() string { //计算总页数 var totalPageNum = int(math.Ceil(float64(p.Total) / float64(p.Pernum))) + lang := p.getLang() + //首页链接 var firstLink string //上一页链接 @@ -62,20 +66,20 @@ func (p *Pagination) Pages() string { //首页和上一页链接 if pagenum > 1 { - firstLink = fmt.Sprintf(`
  • 首页
  • `, p.pageURL("1")) - prevLink = fmt.Sprintf(`
  • 上一页
  • `, p.pageURL(strconv.Itoa(pagenum-1))) + firstLink = fmt.Sprintf(`
  • %s
  • `, p.pageURL("1"), i18n.Tr(lang, "page.first")) + prevLink = fmt.Sprintf(`
  • %s
  • `, p.pageURL(strconv.Itoa(pagenum-1)), i18n.Tr(lang, "page.prev")) } else { - firstLink = `
  • 首页
  • ` - prevLink = `
  • 上一页
  • ` + firstLink = fmt.Sprintf(`
  • %s
  • `, i18n.Tr(lang, "page.first")) + prevLink = fmt.Sprintf(`
  • %s
  • `, i18n.Tr(lang, "page.prev")) } //末页和下一页 if pagenum < totalPageNum { - lastLink = fmt.Sprintf(`
  • 末页
  • `, p.pageURL(strconv.Itoa(totalPageNum))) - nextLink = fmt.Sprintf(`
  • 下一页
  • `, p.pageURL(strconv.Itoa(pagenum+1))) + lastLink = fmt.Sprintf(`
  • %s
  • `, p.pageURL(strconv.Itoa(totalPageNum)), i18n.Tr(lang, "page.last")) + nextLink = fmt.Sprintf(`
  • %s
  • `, p.pageURL(strconv.Itoa(pagenum+1)), i18n.Tr(lang, "page.next")) } else { - lastLink = `
  • 末页
  • ` - nextLink = `
  • 下一页
  • ` + lastLink = fmt.Sprintf(`
  • %s
  • `, i18n.Tr(lang, "page.last")) + nextLink = fmt.Sprintf(`
  • %s
  • `, i18n.Tr(lang, "page.next")) } //生成中间页码链接 @@ -112,3 +116,18 @@ func (p *Pagination) pageURL(page string) string { return u.String() } +func (p *Pagination) getLang() string { + lang := beego.AppConfig.String("default_lang") + ulang := p.Request.FormValue("lang") + if len(ulang) == 0 { + clang, err := p.Request.Cookie("lang") + if err != nil { + return lang + } + ulang = clang.Value + } + if !i18n.IsExist(ulang) { + return lang + } + return ulang +} diff --git a/views/book/index.tpl b/views/book/index.tpl index ab8dec46..234a0151 100644 --- a/views/book/index.tpl +++ b/views/book/index.tpl @@ -5,7 +5,7 @@ - 我的项目 - Powered by MinDoc + {{i18n $.Lang "common.my_project"}} - Powered by MinDoc @@ -28,30 +28,30 @@
    - 项目列表 + {{i18n $.Lang "blog.project_list"}}   - - + +
    - + ${(new Date(item.create_time)).format("yyyy-MM-dd hh:mm:ss")} - ${item.create_name} - ${item.doc_count} - ${item.role_name} + ${item.create_name} + ${item.doc_count} + ${item.role_name}
    @@ -133,49 +133,49 @@