Browse Source

#244#310主题支持中文

tags/v1.21.12.1
ychao_1983 4 years ago
parent
commit
c64d911bd3
5 changed files with 12 additions and 7 deletions
  1. +2
    -0
      models/models.go
  2. +4
    -3
      models/topic.go
  3. +1
    -1
      options/locale/locale_en-US.ini
  4. +1
    -1
      options/locale/locale_zh-CN.ini
  5. +4
    -2
      web_src/js/index.js

+ 2
- 0
models/models.go View File

@@ -185,6 +185,8 @@ func SetEngine() (err error) {
x.SetMaxOpenConns(setting.Database.MaxOpenConns) x.SetMaxOpenConns(setting.Database.MaxOpenConns)
x.SetMaxIdleConns(setting.Database.MaxIdleConns) x.SetMaxIdleConns(setting.Database.MaxIdleConns)
x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime) x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
x.Sync2(tables...)
MigrateCustom(x)
return nil return nil
} }




+ 4
- 3
models/topic.go View File

@@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"strings" "strings"
"unicode/utf8"


"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"


@@ -21,12 +22,12 @@ func init() {
) )
} }


var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
var topicPattern = regexp.MustCompile(`^[\x{4e00}-\x{9fa5}a-z0-9][\x{4e00}-\x{9fa5}a-z0-9-]*$`)


// Topic represents a topic of repositories // Topic represents a topic of repositories
type Topic struct { type Topic struct {
ID int64 ID int64
Name string `xorm:"UNIQUE VARCHAR(25)"`
Name string `xorm:"UNIQUE VARCHAR(105)"`
RepoCount int RepoCount int
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -56,7 +57,7 @@ func (err ErrTopicNotExist) Error() string {


// ValidateTopic checks a topic by length and match pattern rules // ValidateTopic checks a topic by length and match pattern rules
func ValidateTopic(topic string) bool { func ValidateTopic(topic string) bool {
return len(topic) <= 35 && topicPattern.MatchString(topic)
return utf8.RuneCountInString(topic) <= 35 && topicPattern.MatchString(topic)
} }


// SanitizeAndValidateTopics sanitizes and checks an array or topics // SanitizeAndValidateTopics sanitizes and checks an array or topics


+ 1
- 1
options/locale/locale_en-US.ini View File

@@ -1815,7 +1815,7 @@ branch.included = Included
topic.manage_topics = Manage Topics topic.manage_topics = Manage Topics
topic.done = Done topic.done = Done
topic.count_prompt = You can not select more than 25 topics topic.count_prompt = You can not select more than 25 topics
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topic.format_prompt = Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.


[org] [org]
org_name_holder = Organization Name org_name_holder = Organization Name


+ 1
- 1
options/locale/locale_zh-CN.ini View File

@@ -1817,7 +1817,7 @@ branch.included=已包含
topic.manage_topics=管理主题 topic.manage_topics=管理主题
topic.done=保存 topic.done=保存
topic.count_prompt=您最多选择25个主题 topic.count_prompt=您最多选择25个主题
topic.format_prompt=主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
topic.format_prompt=主题必须以汉字、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符


[org] [org]
org_name_holder=组织名称 org_name_holder=组织名称


+ 4
- 2
web_src/js/index.js View File

@@ -4117,7 +4117,9 @@ function initTopicbar() {
topics topics
.last() .last()
.attr('data-value') .attr('data-value')
.match(regExp);
.match(regExp) || topics
.last()
.attr('data-value').length <= 35;
if (!status) { if (!status) {
topics topics
.last() .last()
@@ -4136,7 +4138,7 @@ function initTopicbar() {
rules: [ rules: [
{ {
type: 'validateTopic', type: 'validateTopic',
value: /^[a-z0-9][a-z0-9-]{0,35}$/,
value: /^[\u4e00-\u9fa5a-z0-9][\u4e00-\u9fa5a-z0-9-]{0,105}$/,
prompt: topicPrompts.formatPrompt prompt: topicPrompts.formatPrompt
}, },
{ {


Loading…
Cancel
Save