More translation work. Incomplete.

This commit is contained in:
Sean E. Russell 2020-05-05 08:13:25 -05:00
parent 82f308de93
commit 444d2624ab
7 changed files with 100 additions and 74 deletions

View File

@ -30,7 +30,6 @@ import (
"github.com/xxxserxxx/gotop/v4/devices"
"github.com/xxxserxxx/gotop/v4/layout"
"github.com/xxxserxxx/gotop/v4/logging"
"github.com/xxxserxxx/gotop/v4/widgets"
w "github.com/xxxserxxx/gotop/v4/widgets"
)
@ -122,11 +121,11 @@ func parseArgs() error {
case "devices":
listDevices()
case "keys":
fmt.Println(widgets.KEYBINDS)
fmt.Println(tr.Value("widget.help"))
case "widgets":
fmt.Println(_widgets)
default:
fmt.Printf(tr.Value("errors.unknownopt", *list))
fmt.Printf(tr.Value("error.unknownopt", *list))
os.Exit(1)
}
os.Exit(0)
@ -134,7 +133,7 @@ func parseArgs() error {
if *wc {
path, err := conf.Write()
if err != nil {
fmt.Println(tr.Value("errors.writefail", err.Error()))
fmt.Println(tr.Value("error.writefail", err.Error()))
os.Exit(1)
}
fmt.Println(tr.Value("help.written", path))
@ -346,7 +345,7 @@ func main() {
if ec > 0 {
if ec < 2 {
logpath := filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE)
fmt.Println(tr.Value("errors.checklog", logpath))
fmt.Println(tr.Value("error.checklog", logpath))
fmt.Println(ioutil.ReadFile(logpath))
}
}
@ -379,13 +378,13 @@ func run() int {
}
err = conf.Load()
if err != nil {
fmt.Println(tr.Value("errors.configparse", err.Error()))
fmt.Println(tr.Value("error.configparse", err.Error()))
return 2
}
// Override with command line arguments
err = parseArgs()
if err != nil {
fmt.Println(tr.Value("errors.cliparse", err.Error()))
fmt.Println(tr.Value("error.cliparse", err.Error()))
return 2
}
@ -422,7 +421,7 @@ func run() int {
defer ui.Close()
setDefaultTermuiColors(conf) // done before initializing widgets to allow inheriting colors
help = w.NewHelpMenu()
help = w.NewHelpMenu(tr)
if statusbar {
bar = w.NewStatusBar()
}

View File

@ -35,10 +35,70 @@ List <devices|layouts|colorschemes|paths|keys>
write="Write out a default config file."
[errors]
configparse="failed to parse config file: {0}"
cliparse="parsing CLI args: {0}"
logsetup="failed to setup log file: {0}"
unknownopt="Unknown option \"{0}\"; try layouts, colorschemes, keys, paths, or devices\n"
writefail="Failed to write configuration file: {0}"
checklog="errors encountered; from {0}:"
[error]
configparse="0: failed to parse config file: {0}"
cliparse="1: parsing CLI args: {0}"
logsetup="2: failed to setup log file: {0}"
unknownopt="3: Unknown option \"{0}\"; try layouts, colorschemes, keys, paths, or devices\n"
writefail="4: Failed to write configuration file: {0}"
checklog="5: errors encountered; from {0}:"
metricsetup="6: error setting up {0} metrics: {1}"
nometrics="7: no metrics for {0} {0}"
fatalfetch="8: fatal error fetching {0} info: {1}"
recovfetch="9: recoverable error fetching {0} info; skipping {0}: {0}"
nodevfound="10: no usable {0} found"
setuperr="11: error setting up {0}: {1}"
[widget]
disk=" Disk Usage "
cpu=" CPU Usage "
gauge=" Power Level "
battery=" Battery Status "
batt=
help="""
Quit: q or <C-c>
Process navigation:
- k and <Up>: up
- j and <Down>: down
- <C-u>: half page up
- <C-d>: half page down
- <C-b>: full page up
- <C-f>: full page down
- gg and <Home>: jump to top
- G and <End>: jump to bottom
Process actions:
- <Tab>: toggle process grouping
- dd: kill selected process or group of processes with SIGTERM (15)
- d3: kill selected process or group of processes with SIGQUIT (3)
- d9: kill selected process or group of processes with SIGKILL (9)
Process sorting:
- c: CPU
- m: Mem
- p: PID
Process filtering:
- /: start editing filter
- (while editing):
- <Enter>: accept filter
- <C-c> and <Escape>: clear filter
CPU and Mem graph scaling:
- h: scale in
- l: scale out
Network:
- b: toggle between mbps and scaled bytes per second
"""
[widget.disk]
disk="Disk"
mount="Mount"
used="Used"
free="Free"
rs="R/s"
ws="W/s"

View File

@ -24,7 +24,7 @@ func NewBatteryWidget(horizontalScale int) *BatteryWidget {
LineGraph: ui.NewLineGraph(),
updateInterval: time.Minute,
}
self.Title = " Battery Status "
self.Title = tr.Value("widget.battery")
self.HorizontalScale = horizontalScale
// intentional duplicate
@ -46,7 +46,7 @@ func NewBatteryWidget(horizontalScale int) *BatteryWidget {
func (b *BatteryWidget) EnableMetric() {
bats, err := battery.GetAll()
if err != nil {
log.Printf("error setting up metrics: %v", err)
log.Printf(tr.Value("error.metricsetup", "batt", err.Error()))
return
}
b.metric = make([]prometheus.Gauge, len(bats))
@ -63,7 +63,7 @@ func (b *BatteryWidget) EnableMetric() {
}
func makeID(i int) string {
return "Batt" + strconv.Itoa(i)
return tr.Value("widget.batt") + strconv.Itoa(i)
}
func (b *BatteryWidget) Scale(i int) {
@ -75,7 +75,7 @@ func (b *BatteryWidget) update() {
if err != nil {
switch errt := err.(type) {
case battery.ErrFatal:
log.Printf("fatal error fetching battery info: %v", err)
log.Printf(tr.Value("error.fatalfetch", "batt", err.Error()))
return
case battery.Errors:
batts := make([]*battery.Battery, 0)
@ -83,11 +83,11 @@ func (b *BatteryWidget) update() {
if e == nil {
batts = append(batts, batteries[i])
} else {
log.Printf("recoverable error fetching battery info; skipping battery: %v", e)
log.Printf(tr.Value("error.recovfetch"), "batt", e.Error())
}
}
if len(batts) < 1 {
log.Print("no usable batteries found")
log.Print(tr.Value("error.nodevfound", "batt"))
return
}
batteries = batts

View File

@ -19,7 +19,7 @@ type BatteryGauge struct {
func NewBatteryGauge() *BatteryGauge {
self := &BatteryGauge{Gauge: termui.NewGauge()}
self.Title = " Power Level "
self.Title = tr.Value("widget.gauge")
self.update()
@ -37,7 +37,7 @@ func NewBatteryGauge() *BatteryGauge {
func (b *BatteryGauge) EnableMetric() {
bats, err := battery.GetAll()
if err != nil {
log.Printf("error setting up metrics: %v", err)
log.Printf(tr.Value("error.metricsetup", "power", err.Error()))
return
}
mx := 0.0
@ -60,7 +60,7 @@ func (b *BatteryGauge) update() {
// FIXME: Getting a lot of these in the logs
bats, err := battery.GetAll()
if err != nil {
log.Printf("error setting up batteries: %v", err)
log.Printf(tr.Value("error.setup", "power", err.Error()))
return
}
mx := 0.0

View File

@ -32,7 +32,7 @@ func NewCPUWidget(updateInterval time.Duration, horizontalScale int, showAverage
ShowAverageLoad: showAverageLoad,
ShowPerCPULoad: showPerCPULoad,
}
self.Title = " CPU Usage "
self.Title = tr.Value("cpu")
self.HorizontalScale = horizontalScale
if !(self.ShowAverageLoad || self.ShowPerCPULoad) {
@ -129,7 +129,7 @@ func (cpu *CPUWidget) update() {
cpu.Labels[key] = fmt.Sprintf("%d%%", percent)
if cpu.metric != nil {
if cpu.metric[key] == nil {
log.Printf("no metrics for %s", key)
log.Printf(tr.Value("error.nometrics", "cpu", key))
} else {
cpu.metric[key].Set(float64(percent))
}

View File

@ -38,8 +38,8 @@ func NewDiskWidget() *DiskWidget {
updateInterval: time.Second,
Partitions: make(map[string]*Partition),
}
self.Title = " Disk Usage "
self.Header = []string{"Disk", "Mount", "Used", "Free", "R/s", "W/s"}
self.Title = tr.Value("widget.disk")
self.Header = []string{tr.Value("disk.disk"), tr.Value("disk.mount"), tr.Value("disk.used"), tr.Value("disk.free"), tr.Value("disk.rs"), tr.Value("disk.ws")}
self.ColGap = 2
self.ColResizer = func() {
self.ColWidths = []int{
@ -80,7 +80,7 @@ func (disk *DiskWidget) EnableMetric() {
func (disk *DiskWidget) update() {
partitions, err := psDisk.Partitions(false)
if err != nil {
log.Printf("failed to get disk partitions from gopsutil: %v", err)
log.Printf(tr.Value("error.setup", "disk-partitions", err.Error()))
return
}
@ -125,7 +125,7 @@ func (disk *DiskWidget) update() {
for _, partition := range disk.Partitions {
usage, err := psDisk.Usage(partition.MountPoint)
if err != nil {
log.Printf("failed to get partition usage statistics from gopsutil: %v. partition: %v", err, partition)
log.Printf(tr.Value("error.recovfetch", "partition-"+partition.MountPoint+"-usage", err.Error()))
continue
}
partition.UsedPercent = uint32(usage.UsedPercent + 0.5)
@ -134,7 +134,7 @@ func (disk *DiskWidget) update() {
ioCounters, err := psDisk.IOCounters(partition.Device)
if err != nil {
log.Printf("failed to get partition read/write info from gopsutil: %v. partition: %v", err, partition)
log.Printf(tr.Value("error.recovfetch", "partition-"+partition.Device+"-rw", err.Error()))
continue
}
ioCounter := ioCounters[strings.Replace(partition.Device, "/dev/", "", -1)]
@ -176,7 +176,7 @@ func (disk *DiskWidget) update() {
disk.Rows[i][5] = partition.BytesWrittenRecently
if disk.metric != nil {
if disk.metric[key] == nil {
log.Printf("ERROR: missing metric %s", key)
log.Printf(tr.Value("error.nometrics", "disk", key))
} else {
disk.metric[key].Set(float64(partition.UsedPercent) / 100.0)
}

View File

@ -5,52 +5,19 @@ import (
"strings"
ui "github.com/gizak/termui/v3"
"github.com/xxxserxxx/lingo"
)
// KEYBINDS is the help text for the in-program shortcuts
const KEYBINDS = `
Quit: q or <C-c>
Process navigation:
- k and <Up>: up
- j and <Down>: down
- <C-u>: half page up
- <C-d>: half page down
- <C-b>: full page up
- <C-f>: full page down
- gg and <Home>: jump to top
- G and <End>: jump to bottom
Process actions:
- <Tab>: toggle process grouping
- dd: kill selected process or group of processes with SIGTERM (15)
- d3: kill selected process or group of processes with SIGQUIT (3)
- d9: kill selected process or group of processes with SIGKILL (9)
Process sorting:
- c: CPU
- m: Mem
- p: PID
Process filtering:
- /: start editing filter
- (while editing):
- <Enter>: accept filter
- <C-c> and <Escape>: clear filter
CPU and Mem graph scaling:
- h: scale in
- l: scale out
Network:
- b: toggle between mbps and scaled bytes per second
`
var tr lingo.Translations
var keyBinds string
type HelpMenu struct {
ui.Block
}
func NewHelpMenu() *HelpMenu {
func NewHelpMenu(tra lingo.Translations) *HelpMenu {
tr = tra
keyBinds = tr.Value("widgets.help")
return &HelpMenu{
Block: *ui.NewBlock(),
}
@ -58,12 +25,12 @@ func NewHelpMenu() *HelpMenu {
func (help *HelpMenu) Resize(termWidth, termHeight int) {
textWidth := 53
for _, line := range strings.Split(KEYBINDS, "\n") {
for _, line := range strings.Split(keyBinds, "\n") {
if textWidth < len(line) {
textWidth = len(line) + 2
}
}
textHeight := strings.Count(KEYBINDS, "\n") + 1
textHeight := strings.Count(keyBinds, "\n") + 1
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
@ -73,7 +40,7 @@ func (help *HelpMenu) Resize(termWidth, termHeight int) {
func (help *HelpMenu) Draw(buf *ui.Buffer) {
help.Block.Draw(buf)
for y, line := range strings.Split(KEYBINDS, "\n") {
for y, line := range strings.Split(keyBinds, "\n") {
for x, rune := range line {
buf.SetCell(
ui.NewCell(rune, ui.Theme.Default),