Skip to content

Commit

Permalink
refactor: 调整部分翻译项
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Mar 8, 2024
1 parent 4f0144f commit 9a32c07
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Content-Type 则可以有向服务器指定提交内容的文档类型和字符

框架根据 [RFC7807](https://datatracker.ietf.org/doc/html/rfc7807) 提供了一种输出错误信息内容的机制。

## 中间件
## 插件

- <https://github.com/issue9/middleware> 提供了常用的中间件
- <https://github.com/issue9/filter> 提供了常用的验证方法
- <https://github.com/issue9/webuse> 提供了常用的中间件和插件
- <https://github.com/issue9/webfilter> 提供了常用的验证和修正数据的方法

## 工具

Expand Down
2 changes: 1 addition & 1 deletion cmd/web/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/getkin/kin-openapi v0.123.0
github.com/issue9/assert/v4 v4.1.1
github.com/issue9/cmdopt v0.13.1
github.com/issue9/localeutil v0.26.4
github.com/issue9/localeutil v0.26.5
github.com/issue9/logs/v7 v7.5.0
github.com/issue9/query/v3 v3.1.3
github.com/issue9/source v0.8.2
Expand Down
4 changes: 2 additions & 2 deletions cmd/web/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ github.com/issue9/conv v1.3.5 h1:UWeA+Zqp5vjNDLrmhLhaXPjS1hL8gh4quX6Shk5njKQ=
github.com/issue9/conv v1.3.5/go.mod h1:lkZYMyrmxy+HK//N4eLmwUl9mCwj0zgeTjnxgl/w7hM=
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
github.com/issue9/localeutil v0.26.4 h1:rfBC3YAt9PLHXHc5unreZpYjlEt+xCnVOUr7QDAveiw=
github.com/issue9/localeutil v0.26.4/go.mod h1:BJXJwcAT9CyyVZOlqfmq+B5FcPbqGxGjYnTYbVuiMM8=
github.com/issue9/localeutil v0.26.5 h1:e78b6cOOtgzfb4g4U9uPLC8QyK6Lux+s7ZiQe+6iM1A=
github.com/issue9/localeutil v0.26.5/go.mod h1:BJXJwcAT9CyyVZOlqfmq+B5FcPbqGxGjYnTYbVuiMM8=
github.com/issue9/logs/v7 v7.5.0 h1:IAzqaRXuhNzTvoZVwFJWnWOxCiqhsiqxOt3GuAvJaWQ=
github.com/issue9/logs/v7 v7.5.0/go.mod h1:zPhcpznbDmfApbtrZHeHDvngfNAcuNhgo9pJfKD8nXY=
github.com/issue9/mux/v7 v7.4.1 h1:FG5iu44zd4GVIdzj7/oZgDYBaXnsRnrXWMZANcNhVIk=
Expand Down
3 changes: 0 additions & 3 deletions cmd/web/locales/und.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ messages:
- key: ignore %s
message:
msg: ignore %s
- key: invalid format
message:
msg: invalid format
- key: invalid http method %s
message:
msg: invalid http method %s
Expand Down
3 changes: 0 additions & 3 deletions cmd/web/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ messages:
- key: ignore %s
message:
msg: 忽略 %s
- key: invalid format
message:
msg: 无效的格式
- key: invalid http method %s
message:
msg: 无效的请求方法 %s
Expand Down
3 changes: 2 additions & 1 deletion cmd/web/restdoc/parser/restdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/issue9/version"
"github.com/issue9/web"
"github.com/issue9/web/locales"

"github.com/issue9/web/cmd/web/git"
"github.com/issue9/web/cmd/web/restdoc/openapi"
Expand Down Expand Up @@ -384,7 +385,7 @@ func (p *Parser) parseOpenAPI(target *openapi.OpenAPI, suffix, filename string,
modCache := filepath.Join(build.Default.GOPATH, "pkg", "mod")
uri = &url.URL{Path: filepath.Join(modCache, words[0], words[1])}
default:
p.l.Error(web.StringPhrase("invalid format"), filename, ln)
p.l.Error(locales.InvalidFormat, filename, ln)
return
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/issue9/config v0.6.2
github.com/issue9/conv v1.3.5
github.com/issue9/errwrap v0.3.2
github.com/issue9/localeutil v0.26.4
github.com/issue9/localeutil v0.26.5
github.com/issue9/logs/v7 v7.5.0
github.com/issue9/mux/v7 v7.4.1
github.com/issue9/query/v3 v3.1.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/issue9/conv v1.3.5 h1:UWeA+Zqp5vjNDLrmhLhaXPjS1hL8gh4quX6Shk5njKQ=
github.com/issue9/conv v1.3.5/go.mod h1:lkZYMyrmxy+HK//N4eLmwUl9mCwj0zgeTjnxgl/w7hM=
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
github.com/issue9/localeutil v0.26.4 h1:rfBC3YAt9PLHXHc5unreZpYjlEt+xCnVOUr7QDAveiw=
github.com/issue9/localeutil v0.26.4/go.mod h1:BJXJwcAT9CyyVZOlqfmq+B5FcPbqGxGjYnTYbVuiMM8=
github.com/issue9/localeutil v0.26.5 h1:e78b6cOOtgzfb4g4U9uPLC8QyK6Lux+s7ZiQe+6iM1A=
github.com/issue9/localeutil v0.26.5/go.mod h1:BJXJwcAT9CyyVZOlqfmq+B5FcPbqGxGjYnTYbVuiMM8=
github.com/issue9/logs/v7 v7.5.0 h1:IAzqaRXuhNzTvoZVwFJWnWOxCiqhsiqxOt3GuAvJaWQ=
github.com/issue9/logs/v7 v7.5.0/go.mod h1:zPhcpznbDmfApbtrZHeHDvngfNAcuNhgo9pJfKD8nXY=
github.com/issue9/mux/v7 v7.4.1 h1:FG5iu44zd4GVIdzj7/oZgDYBaXnsRnrXWMZANcNhVIk=
Expand Down
13 changes: 9 additions & 4 deletions locales/locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var Locales = []fs.FS{

// 一些多处用到的翻译项
const (
InvalidFormat = localeutil.StringPhrase("invalid format")
InvalidValue = localeutil.StringPhrase("invalid value")
CanNotBeEmpty = localeutil.StringPhrase("can not be empty")
DuplicateValue = localeutil.StringPhrase("duplicate value")
Expand All @@ -43,17 +44,21 @@ const (
)

// ShouldGreatThan 返回必须大于 n 的翻译项
func ShouldGreatThan(n int) localeutil.Stringer {
return localeutil.Phrase("should great than %d", n)
}
func ShouldGreatThan(n int) localeutil.Stringer { return localeutil.Phrase("should great than %d", n) }

//---------------------------- 以下为本地化的错误实例 -----------------------------

var (
errInvalidFormat = localeutil.Error("invalid format")
errInvalidValue = localeutil.Error("invalid value")
errCanNotBeEmpty = localeutil.Error("can not be empty")
errNotFound = localeutil.Error("not found")
)

func ErrInvalidFormat() error { return errInvalidFormat }

func ErrInvalidValue() error { return errInvalidValue }

func ErrCanNotBeEmpty() error { return errCanNotBeEmpty }

func ErrNotFound(s string) error { return localeutil.Error("%s not found", s) }
func ErrNotFound() error { return errNotFound }
9 changes: 6 additions & 3 deletions locales/und.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
id: und
messages:
- key: '%s not found'
message:
msg: '%s not found'
- key: SSE keep alive cron
message:
msg: SSE keep alive cron
Expand Down Expand Up @@ -30,6 +27,9 @@ messages:
- key: invalid data %s
message:
msg: invalid data %s
- key: invalid format
message:
msg: invalid format
- key: invalid sse format %s
message:
msg: invalid sse format %s
Expand All @@ -39,6 +39,9 @@ messages:
- key: no available peer
message:
msg: no available peer
- key: not found
message:
msg: not found
- key: not found charset for %s
message:
msg: not found charset for %s
Expand Down
9 changes: 6 additions & 3 deletions locales/zh-CN.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
id: zh-CN
messages:
- key: '%s not found'
message:
msg: '%s 不存在'
- key: SSE keep alive cron
message:
msg: SSE 向已链接用户发送的心跳包
Expand Down Expand Up @@ -30,6 +27,9 @@ messages:
- key: invalid data %s
message:
msg: invalid data %s
- key: invalid format
message:
msg: 无效的格式
- key: invalid sse format %s
message:
msg: '无效的 SSE 格式: %s'
Expand All @@ -39,6 +39,9 @@ messages:
- key: no available peer
message:
msg: 没有有效的节点
- key: not found
message:
msg: 未找到
- key: not found charset for %s
message:
msg: 未找到符合报头 %s 的字符集
Expand Down
4 changes: 2 additions & 2 deletions server/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (conf *configOf[T]) sanitizeCompresses() *web.FieldError {
enc, found := compressorFactory.get(e.ID)
if !found {
field := "compresses[" + strconv.Itoa(index) + "].id"
return web.NewFieldError(field, locales.ErrNotFound(e.ID))
return web.NewFieldError(field, locales.ErrNotFound())
}

conf.compressors = append(conf.compressors, &Compression{
Expand All @@ -230,7 +230,7 @@ func (conf *configOf[T]) sanitizeMimetypes() *web.FieldError {
for index, item := range conf.Mimetypes {
m, found := mimetypesFactory.get(item.Target)
if !found {
return web.NewFieldError("mimetypes["+strconv.Itoa(index)+"].target", locales.ErrNotFound(item.Target))
return web.NewFieldError("mimetypes["+strconv.Itoa(index)+"].target", locales.ErrNotFound())
}

ms = append(ms, &Mimetype{
Expand Down
4 changes: 2 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func exists(p string) bool {

func (cert *certificateConfig) sanitize() *web.FieldError {
if !exists(cert.Cert) {
return web.NewFieldError("cert", locales.ErrNotFound(cert.Cert))
return web.NewFieldError("cert", locales.ErrNotFound())
}

if !exists(cert.Key) {
return web.NewFieldError("key", locales.ErrNotFound(cert.Key))
return web.NewFieldError("key", locales.ErrNotFound())
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions server/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (conf *logsConfig) buildHandler() (logs.Handler, []func() error, *web.Field

f, found := logHandlersFactory.get(item.Type)
if !found {
return nil, nil, web.NewFieldError("handlers[0].type", locales.ErrNotFound(item.Type))
return nil, nil, web.NewFieldError("handlers[0].type", locales.ErrNotFound())
}

ww, c, err := f(item.Args)
Expand All @@ -284,7 +284,7 @@ func (conf *logsConfig) buildHandler() (logs.Handler, []func() error, *web.Field

f, found := logHandlersFactory.get(w.Type)
if !found {
return nil, nil, web.NewFieldError(field+".type", locales.ErrNotFound(w.Type))
return nil, nil, web.NewFieldError(field+".type", locales.ErrNotFound())
}

ww, c, err := f(w.Args)
Expand Down
6 changes: 3 additions & 3 deletions server/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (conf *configOf[T]) buildMicro(c web.Cache) *web.FieldError {
for i, m := range conf.Mappers {
mm, found := routerMatcherFactory.get(m.Matcher)
if !found {
return web.NewFieldError("mappers["+strconv.Itoa(i)+"].matcher", locales.ErrNotFound(m.Matcher))
return web.NewFieldError("mappers["+strconv.Itoa(i)+"].matcher", locales.ErrNotFound())
}
conf.mapper[m.Name] = mm(strings.Split(m.Args, ",")...)
}
Expand All @@ -111,12 +111,12 @@ func (conf *configOf[T]) buildMicro(c web.Cache) *web.FieldError {
func (r *registryConfig) build(c web.Cache) *web.FieldError {
t, found := typeFactory.get(r.Type)
if !found {
return web.NewFieldError("type", locales.ErrNotFound(r.Type))
return web.NewFieldError("type", locales.ErrNotFound())
}

s, found := strategyFactory.get(r.Strategy)
if !found {
return web.NewFieldError("strategy", locales.ErrNotFound(r.Strategy))
return web.NewFieldError("strategy", locales.ErrNotFound())
}
r.s = s

Expand Down
2 changes: 1 addition & 1 deletion web.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// Version 当前框架的版本
const Version = "0.87.3"
const Version = "0.87.4"

type (
Logger = logs.Logger
Expand Down

0 comments on commit 9a32c07

Please sign in to comment.