Skip to content

Commit

Permalink
Merge pull request #44 from k1LoW/use-embed
Browse files Browse the repository at this point in the history
Use go:embed for i18n files
  • Loading branch information
k1LoW authored Apr 2, 2024
2 parents bb24db8 + 704f3f4 commit 75d55c5
Show file tree
Hide file tree
Showing 9 changed files with 664 additions and 941 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ sheer-heart-attack
sheer-heart-attack-logs
*.log
coverage.out
packrd
options/options-packr.go
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ before:
hooks:
- go mod download
- go mod tidy
- packr2
builds:
-
id: killer-q-darwin
Expand Down
1,018 changes: 653 additions & 365 deletions CREDITS

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ lint:
golangci-lint run ./...

build:
packr2
go build -ldflags="$(BUILD_LDFLAGS)"
packr2 clean

depsdev:
go install github.com/gobuffalo/packr/v2/packr2@v2.8.3
go install github.com/Songmu/ghch/cmd/ghch@latest
go install github.com/Songmu/gocredits/cmd/gocredits@latest

Expand Down
11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/BurntSushi/toml v1.2.1
github.com/Songmu/prompter v0.5.1
github.com/antonmedv/expr v1.9.0
github.com/gobuffalo/packr/v2 v2.8.3
github.com/k1LoW/duration v1.2.0
github.com/k1LoW/exec v0.2.0
github.com/k1LoW/metr v0.10.0
Expand All @@ -23,15 +22,9 @@ require (

require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gobuffalo/logger v1.0.6 // indirect
github.com/gobuffalo/packd v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/markbates/errx v1.1.0 // indirect
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
Expand All @@ -40,4 +33,6 @@ require (
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
557 changes: 0 additions & 557 deletions go.sum

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
13 changes: 8 additions & 5 deletions options/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package options

import (
"embed"
"errors"
"fmt"
"os"
Expand All @@ -9,7 +10,6 @@ import (

"github.com/BurntSushi/toml"
"github.com/Songmu/prompter"
"github.com/gobuffalo/packr/v2"
"github.com/k1LoW/metr/metrics"
"github.com/labstack/gommon/color"
"github.com/nicksnyder/go-i18n/v2/i18n"
Expand All @@ -20,6 +20,9 @@ import (

const CollectInterval = time.Duration(500) * time.Millisecond

//go:embed i18n/*.toml
var i18nFS embed.FS

type Options struct {
pid int32
name string
Expand Down Expand Up @@ -49,16 +52,16 @@ func NewOptions(
nonInteractive bool,
lang string,
) (*Options, error) {
box := packr.New("i18n", "../i18n")

bundle := i18n.NewBundle(language.English)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
for _, l := range langs {
path := fmt.Sprintf("%s.toml", l.String())
d, err := box.Find(path)
path := fmt.Sprintf("i18n/%s.toml", l.String())
b, err := i18nFS.ReadFile(path)
if err != nil {
return nil, err
}
bundle.MustParseMessageFileBytes(d, path)
bundle.MustParseMessageFileBytes(b, path)
}
matched, _, _ := matcher.Match(language.Make(lang))

Expand Down

0 comments on commit 75d55c5

Please sign in to comment.