Преглед на файлове

refactor, fix bug and update i18n(search), to be continue

shiqstone преди 4 години
родител
ревизия
25e06a767b
променени са 5 файла, в които са добавени 43 реда и са изтрити 17 реда
  1. 12 0
      conf/lang/en-us.ini
  2. 13 1
      conf/lang/zh-cn.ini
  3. 6 4
      controllers/SearchController.go
  4. 1 1
      views/items/list.tpl
  5. 11 11
      views/search/index.tpl

+ 12 - 0
conf/lang/en-us.ini

@@ -363,6 +363,18 @@ creator = Creator
 create_time = Create time
 no_project_space = No Project Space
 
+[search]
+title = Search
+search_title = Show search result for %s
+doc = document
+prj = project
+blog = blog
+from_proj = from project
+from_blog = from blog
+author = author
+update_time = update time
+no_result = No search result
+
 [page]
 first = first
 last = last

+ 13 - 1
conf/lang/zh-cn.ini

@@ -356,13 +356,25 @@ ft_update_time = 更新时间:
 prj_space_list = 项目空间列表
 prj_space_list_of = 项目空间%s的项目列表
 search_title = 显示项目空间为"%s"的项目
-authro = 作者
+author = 作者
 no_project = 暂无项目
 prj_amount = 项目数量
 creator = 创建人
 create_time = 创建时间
 no_project_space = 没有项目空间
 
+[search]
+title = 搜索
+search_title = 显示"%s"的搜索结果
+doc = 文档
+prj = 项目
+blog = 文章
+from_proj = 来自项目
+from_blog = 来自文章
+author = 作者
+update_time = 更新时间
+no_result = 暂无相关搜索结果
+
 [page]
 first = 首页
 last = 末页

+ 6 - 4
controllers/SearchController.go

@@ -1,10 +1,12 @@
 package controllers
 
 import (
-	"github.com/astaxie/beego/logs"
 	"strconv"
 	"strings"
 
+	"github.com/astaxie/beego/logs"
+	"github.com/beego/i18n"
+
 	"github.com/mindoc-org/mindoc/conf"
 	"github.com/mindoc-org/mindoc/models"
 	"github.com/mindoc-org/mindoc/utils"
@@ -87,16 +89,16 @@ func (c *SearchController) User() {
 	key := c.Ctx.Input.Param(":key")
 	keyword := strings.TrimSpace(c.GetString("q"))
 	if key == "" || keyword == "" {
-		c.JsonResult(404, "参数错误")
+		c.JsonResult(404, i18n.Tr(c.Lang, "message.param_error"))
 	}
 	keyword = sqltil.EscapeLike(keyword)
 
 	book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId)
 	if err != nil {
 		if err == models.ErrPermissionDenied {
-			c.JsonResult(403, "没有权限")
+			c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission"))
 		}
-		c.JsonResult(500, "项目不存在")
+		c.JsonResult(500, i18n.Tr(c.Lang, "message.item_not_exist"))
 	}
 
 	//members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccount(book.BookId, 10, "%"+keyword+"%")

+ 1 - 1
views/items/list.tpl

@@ -36,7 +36,7 @@
                         </dd>
                         <dd>
                             <span class="author">
-                                <b class="text">{{i18n .Lang "project.author"}}</b>
+                                <b class="text">{{i18n $.Lang "project.author"}}</b>
                                 <b class="text">-</b>
                                 <b class="text">{{if eq $item.RealName "" }}{{$item.CreateName}}{{else}}{{$item.RealName}}{{end}}</b>
                             </span>

+ 11 - 11
views/search/index.tpl

@@ -5,7 +5,7 @@
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
 
-    <title>搜索 - Powered by MinDoc</title>
+    <title>{{i18n .Lang "search.title"}} - Powered by MinDoc</title>
     <meta name="keywords" content="MinDoc,文档在线管理系统,WIKI,wiki,wiki在线,文档在线管理,接口文档在线管理,接口文档管理,{{.Keyword}}">
     <meta name="description" content="MinDoc文档在线管理系统 {{.site_description}}">
     <!-- Bootstrap -->
@@ -19,7 +19,7 @@
     {{template "widgets/header.tpl" .}}
     <div class="container manual-body">
         <div class="search-head">
-            <strong class="search-title">显示"{{.Keyword}}"的搜索结果</strong>
+            <strong class="search-title">{{i18n .Lang "search.search_title" .Keyword}}</strong>
         </div>
         <div class="row">
             <div class="manual-list">
@@ -27,13 +27,13 @@
                 <div class="search-item">
                     <div class="title">
                 {{if eq $item.SearchType "document"}}
-                    <span class="label mark-doc">文档</span>
+                    <span class="label mark-doc">{{i18n $.Lang "search.doc"}}</span>
                         <a href="{{urlfor "DocumentController.Read" ":key" $item.BookIdentify ":id" $item.Identify}}" title="{{$item.DocumentName}}" target="_blank">{{str2html $item.DocumentName}}</a>
                  {{else if eq $item.SearchType "book"}}
-                    <span class="label mark-book">项目</span>
+                    <span class="label mark-book">{{i18n $.Lang "search.prj"}}</span>
                     <a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" title="{{$item.BookName}}" target="_blank"> {{str2html $item.DocumentName}}</a>
                 {{else}}
-                    <span class="label mark-blog">文章</span>
+                    <span class="label mark-blog">{{i18n $.Lang "search.blog"}}</span>
                         <a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" title="{{$item.DocumentName}}" target="_blank"> {{str2html $item.DocumentName}}</a>
                 {{end}}
                     </div>
@@ -42,20 +42,20 @@
                     </div>
                     <div class="source">
                         {{if eq $item.SearchType "document"}}
-                        <span class="item">来自项目:<a href="{{urlfor "DocumentController.Index" ":key" $item.BookIdentify}}" target="_blank">{{$item.BookName}}</a></span>
+                        <span class="item">{{i18n $.Lang "search.from_proj"}}:<a href="{{urlfor "DocumentController.Index" ":key" $item.BookIdentify}}" target="_blank">{{$item.BookName}}</a></span>
                         {{else if eq $item.SearchType "book"}}
-                            <span class="item">项目:<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" target="_blank">{{$item.BookName}}</a></span>
+                            <span class="item">{{i18n $.Lang "search.prj"}}:<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" target="_blank">{{$item.BookName}}</a></span>
                         {{else}}
-                        <span class="item">来自文章:<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" target="_blank">{{$item.BookName}}</a></span>
+                        <span class="item">{{i18n $.Lang "search.from_blog"}}:<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" target="_blank">{{$item.BookName}}</a></span>
                         {{end}}
-                        <span class="item">作者:{{$item.Author}}</span>
-                        <span class="item">更新时间:{{date_format  $item.ModifyTime "2006-01-02 15:04:05"}}</span>
+                        <span class="item">{{i18n $.Lang "search.author"}}:{{$item.Author}}</span>
+                        <span class="item">{{i18n $.Lang "search.update_time"}}:{{date_format  $item.ModifyTime "2006-01-02 15:04:05"}}</span>
                     </div>
                 </div>
                 {{else}}
                 <div class="search-empty">
                     <img src="{{cdnimg "/static/images/search_empty.png"}}" class="empty-image">
-					<span class="empty-text">暂无相关搜索结果</span>
+					<span class="empty-text">{{i18n .Lang "search.no_result"}}</span>
                 </div>
                 {{end}}
                 <nav class="pagination-container">