Skip to content

Commit

Permalink
feat: 更多的翻译内容
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Aug 22, 2021
1 parent 1be9e89 commit 6a272a3
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/issue9/assert v1.4.1
github.com/issue9/cmdopt v0.7.0
github.com/issue9/errwrap v0.2.0
github.com/issue9/localeutil v0.2.1
github.com/issue9/localeutil v0.3.0
github.com/issue9/sliceutil v0.7.0
github.com/issue9/term/v2 v2.1.4
github.com/issue9/validation v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/issue9/cmdopt v0.7.0/go.mod h1:I5NRZX40jVzM/zJPx8fkHqwv2+b5knyD8roJjE
github.com/issue9/errwrap v0.1.1/go.mod h1:H9mdt7KifDebeRecMn5yt7F25f+4N0V2sqIqyZnNjzQ=
github.com/issue9/errwrap v0.2.0 h1:EPisAVHfGj8ZnR3aNlLFpih/ahDWdMXTOOA+3QaELpk=
github.com/issue9/errwrap v0.2.0/go.mod h1:yudSKP/VtwvbW8hD9riNxJd8sAAzgJUgjllibgHqdJg=
github.com/issue9/localeutil v0.2.1 h1:NXnp3fgVHyzoZwmRQtWnRIEkYs8sfOQv6MlqLLZOrqw=
github.com/issue9/localeutil v0.2.1/go.mod h1:1hx4Qo57RAQgRSy0zihp6XKTkTbaAVu26Qc0bz/770s=
github.com/issue9/localeutil v0.3.0 h1:BveqNZ47hUf8ALyDGqxW6ve8NfiwTlSGkm8B1MvJRH8=
github.com/issue9/localeutil v0.3.0/go.mod h1:1hx4Qo57RAQgRSy0zihp6XKTkTbaAVu26Qc0bz/770s=
github.com/issue9/sliceutil v0.6.0/go.mod h1:FUxZQC4oEw6V46afC+JOdCjOv84BA6WBNQRYGS9V4Dg=
github.com/issue9/sliceutil v0.7.0 h1:PN2W75vYZeJir/cte+H5KBdfYz03hYcmdtSM8Wp0PdM=
github.com/issue9/sliceutil v0.7.0/go.mod h1:FUxZQC4oEw6V46afC+JOdCjOv84BA6WBNQRYGS9V4Dg=
Expand Down
15 changes: 9 additions & 6 deletions internal/cmd/preview/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/fsnotify/fsnotify"
"golang.org/x/text/message"

"github.com/caixw/blogit"
"github.com/caixw/blogit/builder"
Expand All @@ -22,6 +23,8 @@ import (

// options 启动服务的参数选项
type options struct {
p *message.Printer

// 项目的源码目录
// 如果为空,则会采用 ./ 作为默认值。
source string
Expand Down Expand Up @@ -82,7 +85,7 @@ func (o *options) parseURL() error {
case "http", "":
o.addr = ":80"
default:
return fmt.Errorf("不支持协议:%s", scheme)
return fmt.Errorf(o.p.Sprintf("preview unknown protocol", scheme))
}
} else {
o.addr = ":" + o.addr
Expand Down Expand Up @@ -111,7 +114,7 @@ func (o *options) watch(succ, info, erro *console.Logger) error {
o.b = blogit.NewBuilder(o.destFS, info.AsLogger(), erro.AsLogger())

h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
info.Println("访问 ", r.URL.String())
info.Println(o.p.Sprintf("visit url", r.URL.String()))
o.b.ServeHTTP(w, r)
})
o.srv = &http.Server{Addr: o.addr, Handler: http.StripPrefix(o.path, h)}
Expand Down Expand Up @@ -140,18 +143,18 @@ func (o *options) watch(succ, info, erro *console.Logger) error {
}

if time.Since(o.builded) <= time.Second {
info.Println("watcher.Events:更新太频繁,该监控事件被忽略:", event)
info.Println(o.p.Sprintf("preview ignore", event))
continue
}

info.Println("触发事件:", event, ",开始重新编译!")
info.Println(o.p.Sprintf("preview trigger event", event))

go func() {
if err = o.build(); err != nil {
erro.Println(err)
return
}
succ.Println("重新编译成功")
succ.Println(o.p.Sprintf("preview rebuild success"))
}()
case err := <-watcher.Errors:
erro.Println(err)
Expand All @@ -167,7 +170,7 @@ func (o *options) close() error {
}

func (o *options) serve(info *console.Logger) error {
info.Println("启动服务:", o.addr)
info.Println(o.p.Sprintf("start server", o.addr))

if o.cert != "" && o.key != "" {
return o.srv.ListenAndServeTLS(o.cert, o.key)
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/preview/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"github.com/caixw/blogit/internal/cmd/console"
)

var opt = &options{}
var opt *options

// Init 注册 preview 子命令
func Init(o *cmdopt.CmdOpt, succ, info, erro *console.Logger, p *message.Printer) {
opt = &options{p: p}
fs := o.New("preview", p.Sprintf("preview usage"), func(w io.Writer) error {
if err := opt.watch(succ, info, erro); err != nil {
erro.Println(err)
Expand Down
8 changes: 6 additions & 2 deletions internal/cmd/serve/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"net/http"
"os"

"golang.org/x/text/message"

"github.com/caixw/blogit"
"github.com/caixw/blogit/builder"
"github.com/caixw/blogit/internal/cmd/console"
)

// options 启动服务的参数选项
type options struct {
p *message.Printer

// 项目的源码目录
// 如果为空,采用 ./ 作为默认值。
source string
Expand Down Expand Up @@ -53,12 +57,12 @@ func (o *options) serve(info, erro *console.Logger) error {
}

h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
info.Println("访问 ", r.URL.String())
info.Println(o.p.Sprintf("visit url", r.URL.String()))
b.ServeHTTP(w, r)
})
o.srv = &http.Server{Addr: o.addr, Handler: http.StripPrefix(o.path, h)}

info.Println("启动服务:", o.addr)
info.Println(o.p.Sprintf("start server", o.addr))
if o.cert != "" && o.key != "" {
return o.srv.ListenAndServeTLS(o.cert, o.key)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/caixw/blogit/internal/cmd/console"
)

var opt = &options{}
var opt *options

// Init 注册 serve 子命令
func Init(o *cmdopt.CmdOpt, info, erro *console.Logger, p *message.Printer) {
opt = &options{p: p}

fs := o.New("serve", p.Sprintf("serve usage"), func(w io.Writer) error {
if err := opt.serve(info, erro); err != nil {
erro.Println(err)
Expand Down
32 changes: 30 additions & 2 deletions internal/locale/cmn-hans.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

language: cmn-hans
languages:
- cmn-hans
- und # 作为默认语言

messages:
- key: cmd title
Expand Down Expand Up @@ -135,7 +137,6 @@ messages:
message:
msg: 服务基地址


- key: preview http cert
message:
msg: cert 证书
Expand All @@ -144,6 +145,21 @@ messages:
message:
msg: key 证书

- key: preview rebuild success
message:
msg: 重新编译成功

- key: preview trigger event
message:
msg: 触发事件 %[1]s,开始重新编译!

- key: preview unknown protocol
message:
msg: 未支持的协议 %[1]s

- key: preview ignore
message:
msg: 'watcher.Events: 更新太频繁,该监控事件 %[1]s 被忽略!'

## create

Expand Down Expand Up @@ -173,3 +189,15 @@ messages:
- key: create file
message:
msg: 创建文件 %[1]s



## common

- key: visit url
message:
msg: 访问 URL %[1]s

- key: start server
message:
msg: 启动服务:%[1]s
14 changes: 7 additions & 7 deletions internal/locale/locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ var locales embed.FS
var b *catalog.Builder

func NewPrinter() (*message.Printer, error) {
if b == nil {
b = catalog.NewBuilder()
systag, err := localeutil.SystemLanguageTag()
if err != nil {
return nil, err
}

if b == nil {
matchs, err := fs.Glob(locales, "*.yaml")
if err != nil {
return nil, err
}

b = catalog.NewBuilder()

for _, file := range matchs {
if err := localeutil.LoadMessageFromFS(b, locales, file, yaml.Unmarshal); err != nil {
return nil, err
}
}
}

systag, err := localeutil.SystemLanguageTag()
if err != nil {
return nil, err
}

return message.NewPrinter(systag, message.Catalog(b)), nil
}
2 changes: 1 addition & 1 deletion internal/vars/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package vars

var (
version = "1.5.4" // 版本号,由 goreleaser 负责在编译时更新到最新的 git tag
version = "1.6.0" // 版本号,由 goreleaser 负责在编译时更新到最新的 git tag
metadata string
fullVersion = version
)
Expand Down

0 comments on commit 6a272a3

Please sign in to comment.