Translation files are now bundled.

This commit is contained in:
Sean E. Russell 2020-06-19 10:01:26 -05:00
parent de187a89ae
commit aa828c5790
12 changed files with 435 additions and 13 deletions

View File

@ -69,6 +69,10 @@ Move `gotop` to somewhere in your `$PATH`.
If Go is not installed or is the wrong version, and you don't have root access or don't want to upgrade Go, a script is provided to download Go and the gotop sources, compile gotop, and then clean up. See `scripts/install_without_root.sh`. If Go is not installed or is the wrong version, and you don't have root access or don't want to upgrade Go, a script is provided to download Go and the gotop sources, compile gotop, and then clean up. See `scripts/install_without_root.sh`.
#### go generate
Apple SMC tags are embedded in a text file that is compiled into the executable; the same happens with the language translations. When the file `devices/data/sm.tsv` or any translations in `translations/dicts/` change, `go generate` should be re-run.
## Usage ## Usage
Run with `-h` to get an extensive list of command line arguments. Many of these can be configured by creating a configuration file; see the next section for more information. Key bindings can be viewed while gotop is running by pressing the `?` key, or they can be printed out by using the `--list keys` command. Run with `-h` to get an extensive list of command line arguments. Many of these can be configured by creating a configuration file; see the next section for more information. Key bindings can be viewed while gotop is running by pressing the `?` key, or they can be printed out by using the `--list keys` command.

View File

@ -30,6 +30,7 @@ import (
"github.com/xxxserxxx/gotop/v4/devices" "github.com/xxxserxxx/gotop/v4/devices"
"github.com/xxxserxxx/gotop/v4/layout" "github.com/xxxserxxx/gotop/v4/layout"
"github.com/xxxserxxx/gotop/v4/logging" "github.com/xxxserxxx/gotop/v4/logging"
"github.com/xxxserxxx/gotop/v4/translations"
w "github.com/xxxserxxx/gotop/v4/widgets" w "github.com/xxxserxxx/gotop/v4/widgets"
) )
@ -354,7 +355,7 @@ func main() {
} }
func run() int { func run() int {
ling, err := lingo.New("en_US", "translations", nil) ling, err := lingo.New("en_US", "translations", translations.AssetFile())
if err != nil { if err != nil {
fmt.Printf("failed to load language files: %s\n", err) fmt.Printf("failed to load language files: %s\n", err)
return 2 return 2

View File

@ -1,5 +1,8 @@
package gotop package gotop
//go:generate go-bindata -fs -pkg translations -prefix translations -o translations/dicts.go translations/dicts
//go:generate go-bindata -pkg devices -prefix devices/data -o devices/smc.go devices/data
import ( import (
"bufio" "bufio"
"bytes" "bytes"

View File

@ -1,8 +1,7 @@
// Code generated by go-bindata. // Code generated by go-bindata. (@generated) DO NOT EDIT.
// sources:
// data/smc.tsv
// DO NOT EDIT!
//Package devices generated by go-bindata.// sources:
// devices/data/smc.tsv
package devices package devices
import ( import (
@ -20,7 +19,7 @@ import (
func bindataRead(data []byte, name string) ([]byte, error) { func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data)) gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) return nil, fmt.Errorf("read %q: %v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
@ -28,7 +27,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
clErr := gz.Close() clErr := gz.Close()
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) return nil, fmt.Errorf("read %q: %v", name, err)
} }
if clErr != nil { if clErr != nil {
return nil, err return nil, err
@ -49,21 +48,32 @@ type bindataFileInfo struct {
modTime time.Time modTime time.Time
} }
// Name return file name
func (fi bindataFileInfo) Name() string { func (fi bindataFileInfo) Name() string {
return fi.name return fi.name
} }
// Size return file size
func (fi bindataFileInfo) Size() int64 { func (fi bindataFileInfo) Size() int64 {
return fi.size return fi.size
} }
// Mode return file mode
func (fi bindataFileInfo) Mode() os.FileMode { func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode return fi.mode
} }
// ModTime return file modify time
func (fi bindataFileInfo) ModTime() time.Time { func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime return fi.modTime
} }
// IsDir return file whether a directory
func (fi bindataFileInfo) IsDir() bool { func (fi bindataFileInfo) IsDir() bool {
return false return fi.mode&os.ModeDir != 0
} }
// Sys return file is sys mode
func (fi bindataFileInfo) Sys() interface{} { func (fi bindataFileInfo) Sys() interface{} {
return nil return nil
} }
@ -83,7 +93,7 @@ func smcTsv() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "smc.tsv", size: 3398, mode: os.FileMode(420), modTime: time.Unix(1591711965, 0)} info := bindataFileInfo{name: "smc.tsv", size: 3398, mode: os.FileMode(420), modTime: time.Unix(1592515411, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -182,6 +192,7 @@ type bintree struct {
Func func() (*asset, error) Func func() (*asset, error)
Children map[string]*bintree Children map[string]*bintree
} }
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"smc.tsv": &bintree{smcTsv, map[string]*bintree{}}, "smc.tsv": &bintree{smcTsv, map[string]*bintree{}},
}} }}
@ -232,4 +243,3 @@ func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
} }

View File

@ -1,7 +1,5 @@
package devices package devices
//go:generate go-bindata -pkg devices -prefix data -o smc.go data
import ( import (
"log" "log"
) )

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0 github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0
github.com/shirou/gopsutil v2.20.3+incompatible github.com/shirou/gopsutil v2.20.3+incompatible
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
github.com/xxxserxxx/lingo v1.0.1 github.com/xxxserxxx/lingo v1.1.0
github.com/xxxserxxx/opflag v1.0.5 github.com/xxxserxxx/opflag v1.0.5
golang.org/x/sys v0.0.0-20200316230553-a7d97aace0b0 golang.org/x/sys v0.0.0-20200316230553-a7d97aace0b0
howett.net/plist v0.0.0-20200419221736-3b63eb3a43b5 // indirect howett.net/plist v0.0.0-20200419221736-3b63eb3a43b5 // indirect

2
go.sum
View File

@ -39,6 +39,8 @@ github.com/valyala/histogram v1.0.1 h1:FzA7n2Tz/wKRMejgu3PV1vw3htAklTjjuoI6z3d4K
github.com/valyala/histogram v1.0.1/go.mod h1:lQy0xA4wUz2+IUnf97SivorsJIp8FxsnRd6x25q7Mto= github.com/valyala/histogram v1.0.1/go.mod h1:lQy0xA4wUz2+IUnf97SivorsJIp8FxsnRd6x25q7Mto=
github.com/xxxserxxx/lingo v1.0.1 h1:lPexOb0HEqYB50EaJdjaYFNATT8JhTcXljbQmCuXygE= github.com/xxxserxxx/lingo v1.0.1 h1:lPexOb0HEqYB50EaJdjaYFNATT8JhTcXljbQmCuXygE=
github.com/xxxserxxx/lingo v1.0.1/go.mod h1:C2teIFiBLAmEhpLzRkwk7wP5R0eOoveXVYqD+5KOkAs= github.com/xxxserxxx/lingo v1.0.1/go.mod h1:C2teIFiBLAmEhpLzRkwk7wP5R0eOoveXVYqD+5KOkAs=
github.com/xxxserxxx/lingo v1.1.0 h1:UaA0oNyen0vGWNHD6eow+uCfBu7hhypwb28RxQSnprY=
github.com/xxxserxxx/lingo v1.1.0/go.mod h1:C2teIFiBLAmEhpLzRkwk7wP5R0eOoveXVYqD+5KOkAs=
github.com/xxxserxxx/opflag v1.0.5 h1:2H4Qtl1qe+dSkEcGt+fBe2mQ8z14MgkWPqcLaoa6k90= github.com/xxxserxxx/opflag v1.0.5 h1:2H4Qtl1qe+dSkEcGt+fBe2mQ8z14MgkWPqcLaoa6k90=
github.com/xxxserxxx/opflag v1.0.5/go.mod h1:GWZtb3/tGGj5W1GE/JTyJAuqgxDxl1+jqDGAGM+P/p4= github.com/xxxserxxx/opflag v1.0.5/go.mod h1:GWZtb3/tGGj5W1GE/JTyJAuqgxDxl1+jqDGAGM+P/p4=
golang.org/x/sys v0.0.0-20200316230553-a7d97aace0b0 h1:4Khi5GeNOkZS5DqSBRn4Sy7BE6GuxwOqARPqfurkdNk= golang.org/x/sys v0.0.0-20200316230553-a7d97aace0b0 h1:4Khi5GeNOkZS5DqSBRn4Sy7BE6GuxwOqARPqfurkdNk=

404
translations/dicts.go Normal file

File diff suppressed because one or more lines are too long