mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-16 07:40:44 -07:00
feat: allow language to be passed in argument
This commit is contained in:
parent
7523cec0ce
commit
da5fc22258
10
README.md
10
README.md
@ -12,6 +12,16 @@ Google Translate TUI
|
|||||||
go get && go build
|
go get && go build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Language in argument
|
||||||
|
|
||||||
|
You can pass `-src` and `-dst` in argument to set source and destination language.
|
||||||
|
|
||||||
|
```
|
||||||
|
gtt -src "English" -dst "Chinese (Traditional)"
|
||||||
|
```
|
||||||
|
|
||||||
|
See language on [Google Language support](https://cloud.google.com/translate/docs/languages)
|
||||||
|
|
||||||
## Key Map
|
## Key Map
|
||||||
|
|
||||||
`<C-c>`
|
`<C-c>`
|
||||||
|
39
config.go
39
config.go
@ -1,9 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
srcLangArg *string = flag.String("src", "", "Source Language")
|
||||||
|
dstLangArg *string = flag.String("dst", "", "Destination Language")
|
||||||
|
)
|
||||||
|
|
||||||
// Search XDG_CONFIG_HOME or $HOME/.config
|
// Search XDG_CONFIG_HOME or $HOME/.config
|
||||||
func configInit() {
|
func configInit() {
|
||||||
var defaultConfigPath string
|
var defaultConfigPath string
|
||||||
@ -33,8 +39,17 @@ func configInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
translator.SrcLang = config.GetString("source.language")
|
flag.Parse()
|
||||||
translator.DstLang = config.GetString("destination.language")
|
if len(*srcLangArg) > 0 {
|
||||||
|
translator.SrcLang = *srcLangArg
|
||||||
|
} else {
|
||||||
|
translator.SrcLang = config.GetString("source.language")
|
||||||
|
}
|
||||||
|
if len(*dstLangArg) > 0 {
|
||||||
|
translator.DstLang = *dstLangArg
|
||||||
|
} else {
|
||||||
|
translator.DstLang = config.GetString("destination.language")
|
||||||
|
}
|
||||||
style.Theme = config.GetString("theme")
|
style.Theme = config.GetString("theme")
|
||||||
style.Transparent = config.GetBool("transparent")
|
style.Transparent = config.GetBool("transparent")
|
||||||
style.SetSrcBorderColor(config.GetString("source.borderColor")).
|
style.SetSrcBorderColor(config.GetString("source.borderColor")).
|
||||||
@ -45,6 +60,18 @@ func configInit() {
|
|||||||
func updateConfig() {
|
func updateConfig() {
|
||||||
changed := false
|
changed := false
|
||||||
|
|
||||||
|
// Source language is not passed in argument
|
||||||
|
if len(*srcLangArg) == 0 &&
|
||||||
|
config.GetString("source.language") != translator.SrcLang {
|
||||||
|
changed = true
|
||||||
|
config.Set("source.language", translator.SrcLang)
|
||||||
|
}
|
||||||
|
// Destination language is not passed in argument
|
||||||
|
if len(*dstLangArg) == 0 &&
|
||||||
|
config.GetString("destination.language") != translator.DstLang {
|
||||||
|
changed = true
|
||||||
|
config.Set("destination.language", translator.DstLang)
|
||||||
|
}
|
||||||
if config.GetString("theme") != style.Theme {
|
if config.GetString("theme") != style.Theme {
|
||||||
changed = true
|
changed = true
|
||||||
config.Set("theme", style.Theme)
|
config.Set("theme", style.Theme)
|
||||||
@ -53,18 +80,10 @@ func updateConfig() {
|
|||||||
changed = true
|
changed = true
|
||||||
config.Set("transparent", style.Transparent)
|
config.Set("transparent", style.Transparent)
|
||||||
}
|
}
|
||||||
if config.GetString("source.language") != translator.SrcLang {
|
|
||||||
changed = true
|
|
||||||
config.Set("source.language", translator.SrcLang)
|
|
||||||
}
|
|
||||||
if config.GetString("source.borderColor") != style.SrcBorderStr() {
|
if config.GetString("source.borderColor") != style.SrcBorderStr() {
|
||||||
changed = true
|
changed = true
|
||||||
config.Set("source.borderColor", style.SrcBorderStr())
|
config.Set("source.borderColor", style.SrcBorderStr())
|
||||||
}
|
}
|
||||||
if config.GetString("destination.language") != translator.DstLang {
|
|
||||||
changed = true
|
|
||||||
config.Set("destination.language", translator.DstLang)
|
|
||||||
}
|
|
||||||
if config.GetString("destination.borderColor") != style.DstBorderStr() {
|
if config.GetString("destination.borderColor") != style.DstBorderStr() {
|
||||||
changed = true
|
changed = true
|
||||||
config.Set("destination.borderColor", style.DstBorderStr())
|
config.Set("destination.borderColor", style.DstBorderStr())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user