Skip to content

sortGenerateConst排序 #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/codegen.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/git_toolbox_blame.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions codegen/generate_i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/lazygophers/codegen/state"
"github.com/lazygophers/log"
"github.com/lazygophers/utils/anyx"
"github.com/lazygophers/utils/candy"
"github.com/lazygophers/utils/osx"
"github.com/pterm/pterm"
"io/fs"
Expand Down Expand Up @@ -110,6 +111,13 @@ func GenerateI18nConst(dstLocalize map[string]any, path string) (err error) {

deepKeys([]string{}, dstLocalize)

//sort
keys := make([]string, 0)
for k, _ := range localize {
keys = append(keys, k)
}
keys = candy.Sort(keys)

tpl, err := GetTemplate(TemplateTypeI18nConst)
if err != nil {
log.Errorf("err:%v", err)
Expand All @@ -133,6 +141,7 @@ func GenerateI18nConst(dstLocalize map[string]any, path string) (err error) {
"DirName": filepath.Base(filepath.Dir(path)),
"Localize": localize,
"DeepLocalize": dstLocalize,
"SortedKeys": keys,
})
if err != nil {
log.Errorf("err:%v", err)
Expand Down
4 changes: 2 additions & 2 deletions codegen/template/i18n_const.gtpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package {{ .DirName }}

const ({{ range $key, $value := .Localize}}
I18nTag{{ ToCamel $key }} = `{{ $key }}`{{ end }}
const ({{ range $value := .SortedKeys}}
I18nTag{{ ToCamel $value }} = `{{ $value }}`{{ end }}
)
62 changes: 62 additions & 0 deletions debug.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
project_name: codegen
version: 2
env:
- GO111MODULE=on
- GOSUMDB=sum.golang.google.cn
- CGO_ENABLED=0

builds:
- id: cli
binary: "{{ .ProjectName }}"
tags:
- debug
ldflags:
- -s -w
- --extldflags "-static -fpic"
- -X github.com/lazygophers/utils/app.Name={{ .ProjectName }}
- -X github.com/lazygophers/utils/app.Commit={{ .FullCommit }}
- -X github.com/lazygophers/utils/app.ShortCommit={{ .ShortCommit }}
- -X github.com/lazygophers/utils/app.Branch={{ .Branch }}
- -X github.com/lazygophers/utils/app.Version={{ .Version }}
- -X github.com/lazygophers/utils/app.Tag={{ .Tag }}
- -X github.com/lazygophers/utils/app.BuildDate={{ .Date }}
- -X github.com/lazygophers/utils/app.GoVersion={{ .Env.GOVERSION }}
- -X github.com/lazygophers/utils/app.GoOS={{ .Os }}
- -X github.com/lazygophers/utils/app.Goarch={{ .Arch }}
- -X github.com/lazygophers/utils/app.Goarm={{ .Arm }}
- -X github.com/lazygophers/utils/app.Goamd64={{ .Amd64 }}
- -X github.com/lazygophers/utils/app.Gomips={{ .Mips }}
gcflags:
- -N -l
main: ./cmd/
targets:
- linux_amd64_v3
- linux_arm64
- windows_amd64
- darwin_amd64_v3
- darwin_arm64

archives:
- formats: tar.gz
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
format_overrides:
- goos: windows
formats: zip
files:
- LICENSE
- README.md
- example.codegen.cfg.yaml

#checksum:
# algorithm: sha512
# name_template: '{{ .ProjectName }}_{{ .Version }}.sha512'

source:
enabled: false
files:
- LICENSE
- README.md
- conf.example.yaml
- '*.go'

report_sizes: true
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/emicklei/proto v1.14.1
github.com/go-git/go-git/v5 v5.16.0
github.com/gookit/color v1.5.5-0.20240610061437-fedc17449eaf
github.com/lazygophers/log v0.0.0-20250409033028-0656cc92f9c3
github.com/lazygophers/lrpc v0.0.0-20250420020031-b78cbbe23aaf
github.com/lazygophers/utils v0.0.0-20250430052029-57f0cb71ff66
github.com/lazygophers/log v0.0.0-20250509113414-7f7294f75e89
github.com/lazygophers/lrpc v0.0.0-20250430104923-8731b1b844d6
github.com/lazygophers/utils v0.0.0-20250513102512-2a123236f271
github.com/pelletier/go-toml/v2 v2.2.4
github.com/pterm/pterm v0.12.80
github.com/spf13/cobra v1.9.1
Expand Down Expand Up @@ -49,7 +49,7 @@ require (
github.com/lestrrat-go/strftime v1.1.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a // indirect
github.com/petermattis/goid v0.0.0-20250508124226-395b08cebbdb // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lazygophers/log v0.0.0-20250409033028-0656cc92f9c3 h1:AVJN7JSbMbGMz8fUUMKQUGkbBeGfAmXQP5OM+3524pc=
github.com/lazygophers/log v0.0.0-20250409033028-0656cc92f9c3/go.mod h1:VAgZBW99hWCtU8di03N2znbFaAkPd8OBUkTwuDAaXrs=
github.com/lazygophers/log v0.0.0-20250509113414-7f7294f75e89 h1:a12LqG5jT0tGCCD59KLoEmEJ2rzQLkX8mR25FP2LJEM=
github.com/lazygophers/log v0.0.0-20250509113414-7f7294f75e89/go.mod h1:wunnxf+6ECN2bt8908dbXQmg7TG4W5wvvK/3mEUkKoI=
github.com/lazygophers/lrpc v0.0.0-20250420020031-b78cbbe23aaf h1:5lQJTYRJzPBj2ltUBgaCOK/wDSgtNSpnOEZd6lKmNfE=
github.com/lazygophers/lrpc v0.0.0-20250420020031-b78cbbe23aaf/go.mod h1:OU+hxE/MGkQPmcW4Uqk7g0J7TjgXEybUKIq9fukDi3w=
github.com/lazygophers/lrpc v0.0.0-20250430104923-8731b1b844d6 h1:5895+3o6MOCQYcICi8yHX9pQ1W6XCYIaL1S/iHAsrC0=
github.com/lazygophers/lrpc v0.0.0-20250430104923-8731b1b844d6/go.mod h1:7psAKbQyIMKBF17bTnYkpkxcKAuO2jGA0h3HkGOp5Do=
github.com/lazygophers/utils v0.0.0-20250430052029-57f0cb71ff66 h1:7ZuyULuOJK+FxXJRJzMGxySHM2pMYfSy0JVtJWHeQA4=
github.com/lazygophers/utils v0.0.0-20250430052029-57f0cb71ff66/go.mod h1:SnvRknWaFvV57m3DdfAu8j5msmo6PODjuWOsWpOGrXQ=
github.com/lazygophers/utils v0.0.0-20250513102512-2a123236f271 h1:0DMW9g7fq+PbKh+H7uks6HtZRpNwxvfI3I3cV6gCEfY=
github.com/lazygophers/utils v0.0.0-20250513102512-2a123236f271/go.mod h1:cDHEQbFtDqV8hePzGAtvpHnBGRYCZwqEXnUDhgWVVpg=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
Expand All @@ -120,6 +126,8 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a h1:S+AGcmAESQ0pXCUNnRH7V+bOUIgkSX5qVt2cNKCrm0Q=
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/petermattis/goid v0.0.0-20250508124226-395b08cebbdb h1:3PrKuO92dUTMrQ9dx0YNejC6U/Si6jqKmyQ9vWjwqR4=
github.com/petermattis/goid v0.0.0-20250508124226-395b08cebbdb/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
6 changes: 3 additions & 3 deletions state/i18n_const.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading