Skip to content

Commit e3689f8

Browse files
committed
feat: add Chinese hint
1 parent e8458cd commit e3689f8

2 files changed

Lines changed: 65 additions & 41 deletions

File tree

commit-msg.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import (
99
)
1010

1111
func logAndExit(state MsgState, v ...interface{}) {
12-
a := append([]interface{}{state.Name()}, v...)
1312
if state <= Merge {
14-
log.Printf(state.Hint(), a...)
13+
log.Printf(state.Hint(), v...)
1514
os.Exit(0)
1615
} else if state <= FileMissing {
17-
log.Fatalf(state.Hint(), a...)
16+
log.Fatalf(state.Hint(), v...)
1817
} else {
19-
log.Printf(state.Hint(), a...)
18+
log.Printf(state.Hint(), v...)
2019
log.Fatalf(ruleHint, strings.Join(typeList[:], ", "))
2120
}
2221
}

config.go

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,10 @@ const (
2929
)
3030

3131
var (
32-
msgStates = [...]string{
33-
"Validated",
34-
"Merge",
35-
"ArgumentMissing",
36-
"FileMissing",
37-
"ReadError",
38-
"EmptyMessage",
39-
"EmptyHeader",
40-
"BadHeaderFormat",
41-
"WrongType",
42-
"BodyMissing",
43-
"NoBlankLineBeforeBody",
44-
"LineOverLong",
45-
"UndefindedError",
46-
}
47-
stateHint = [...]string{
48-
"%s: commit message meet the rule.\n",
49-
"%s: merge commit detected,skip check.\n",
50-
"Error %s: commit message file argument missing.\n",
51-
"Error %s: file %s not exists.\n",
52-
"Error %s: read file %s error.\n",
53-
"Error %s: commit message has no content except whitespaces.\n",
54-
"Error %s: header (first line) has no content except whitespaces.\n",
55-
`Error %s: header (first line) not following the rule:
56-
%s
57-
if you can not find any error after check, maybe you use Chinese colon, or lack of whitespace after the colon.`,
58-
"Error %s: %s, should be one of the keywords:\n%s\n",
59-
"Error %s: body has no content except whitespaces.\n",
60-
"Error %s: no empty line between header and body.\n",
61-
"Error %s: the length of line is %d, exceed %d:\n%s\n",
62-
"Error %s: unexpected error occurs, please raise an issue.",
63-
}
64-
typeList = [...]string{
32+
lang = "zh-CN"
33+
stateHint []string
34+
ruleHint string
35+
typeList = [...]string{
6536
"feat", // new feature 新功能
6637
"fix", // fix bug 修复
6738
"docs", // documentation 文档
@@ -73,7 +44,7 @@ if you can not find any error after check, maybe you use Chinese colon, or lack
7344
"revert", // 撤销以前的 commit
7445
"Revert", // 有些工具生成的 revert 首字母大写
7546
}
76-
ruleHint = `Commit message rule as follow:
47+
enRule = `Commit message rule as follow:
7748
<type>(<scope>): <subject>
7849
// empty line
7950
<body>
@@ -82,11 +53,65 @@ if you can not find any error after check, maybe you use Chinese colon, or lack
8253
8354
(<scope>), <body> and <footer> are optional
8455
<type> must be one of %s
85-
more specific instructions, please refer to https://github.com/JayceChant/commit-msg.go`
56+
more specific instructions, please refer to: https://github.com/JayceChant/commit-msg.go`
57+
58+
zhCnRule = `提交信息规范如下:
59+
<type>(<scope>): <subject>
60+
// 空行
61+
<body>
62+
// 空行
63+
<footer>
64+
65+
(<scope>), <body> 和 <footer> 可选
66+
<type> 必须是关键字 %s 之一
67+
更多信息,请参考项目主页: https://github.com/JayceChant/commit-msg.go`
68+
69+
enHint = [...]string{
70+
"Validated: commit message meet the rule.\n",
71+
"Merge: merge commit detected,skip check.\n",
72+
"Error ArgumentMissing: commit message file argument missing.\n",
73+
"Error FileMissing: file %s not exists.\n",
74+
"Error ReadError: read file %s error.\n",
75+
"Error EmptyMessage: commit message has no content except whitespaces.\n",
76+
"Error EmptyHeader: header (first line) has no content except whitespaces.\n",
77+
`Error BadHeaderFormat: header (first line) not following the rule:
78+
%s
79+
if you can not find any error after check, maybe you use Chinese colon, or lack of whitespace after the colon.`,
80+
"Error WrongType: %s, should be one of the keywords:\n%s\n",
81+
"Error BodyMissing: body has no content except whitespaces.\n",
82+
"Error NoBlankLineBeforeBody: no empty line between header and body.\n",
83+
"Error LineOverLong: the length of line is %d, exceed %d:\n%s\n",
84+
"Error UndefindedError: unexpected error occurs, please raise an issue.\n",
85+
}
86+
zhCnHint = [...]string{
87+
"Validated: 提交信息符合规范。\n",
88+
"Merge: 合并提交,跳过规范检查。\n",
89+
"Error ArgumentMissing: 缺少文件参数。\n",
90+
"Error FileMissing: 文件 %s 不存在。\n",
91+
"Error ReadError: 读取 %s 错误。\n",
92+
"Error EmptyMessage: 提交信息没有内容(不包括空白字符)。\n",
93+
"Error EmptyHeader: 标题(第一行)没有内容(不包括空白字符)。\n",
94+
`Error BadHeaderFormat: 标题(第一行)不符合规范:
95+
%s
96+
如果您无法发现错误,请注意是否使用了中文冒号,或者冒号后面缺少空格。`,
97+
"Error WrongType: %s, 类型关键字应为以下选项中的一个:\n%s\n",
98+
"Error BodyMissing: 消息体没有内容(不包括空白字符)。\n",
99+
"Error NoBlankLineBeforeBody: 标题和消息体之间缺少空行。\n",
100+
"Error LineOverLong: 该行长度为 %d, 超出了 %d 的限制:\n%s\n",
101+
"Error UndefindedError: 没有预料到的错误,请提交一个错误报告。\n",
102+
}
86103
)
87104

88-
func (state MsgState) Name() string {
89-
return msgStates[state]
105+
func init() {
106+
// lang = "zh-CN"
107+
switch lang {
108+
case "zh-CN":
109+
stateHint = zhCnHint[:]
110+
ruleHint = zhCnRule
111+
default:
112+
stateHint = enHint[:]
113+
ruleHint = enRule
114+
}
90115
}
91116

92117
func (state MsgState) Hint() string {

0 commit comments

Comments
 (0)