mozhi/cmd/translate.go

97 lines
3.4 KiB
Go
Raw Normal View History

2023-06-24 18:40:57 +00:00
package cmd
import (
"codeberg.org/aryak/simplytranslate/utils"
2023-07-03 11:59:46 +00:00
"fmt"
2023-07-22 14:24:15 +00:00
"github.com/spf13/cobra"
2023-06-24 18:40:57 +00:00
)
var engine string
var query string
var source string
var dest string
var langlist string
var translateCmd = &cobra.Command{
Use: "translate",
Short: "Translate.",
Long: `Translate.`,
Run: func(cmd *cobra.Command, args []string) {
if engine == "reverso" {
if langlist == "sl" {
fmt.Println(utils.LangListReverso(langlist))
} else if langlist == "tl" {
fmt.Println(utils.LangListReverso(langlist))
} else {
fmt.Println(utils.TranslateReverso(dest, source, query))
}
2023-07-03 11:59:46 +00:00
} else if engine == "deepl" {
if langlist == "sl" {
fmt.Println(utils.LangListDeepl(langlist))
} else if langlist == "tl" {
fmt.Println(utils.LangListDeepl(langlist))
} else {
2023-07-23 14:30:20 +00:00
fmt.Println(utils.TranslateDeepl(dest, source, query))
2023-07-03 11:59:46 +00:00
}
} else if engine == "libretranslate" {
if langlist == "sl" {
fmt.Println(utils.LangListLibreTranslate(langlist))
} else if langlist == "tl" {
fmt.Println(utils.LangListLibreTranslate(langlist))
} else {
fmt.Println(utils.TranslateLibreTranslate(dest, source, query))
}
2023-07-22 05:42:26 +00:00
} else if engine == "watson" {
if langlist == "sl" {
fmt.Println(utils.LangListWatson(langlist))
} else if langlist == "tl" {
fmt.Println(utils.LangListWatson(langlist))
} else {
fmt.Println(utils.TranslateWatson(dest, source, query))
}
2023-07-22 14:20:21 +00:00
} else if engine == "yandex" {
if langlist == "sl" {
2023-07-22 14:24:15 +00:00
fmt.Println(utils.LangListYandex(langlist))
2023-07-22 14:20:21 +00:00
} else if langlist == "tl" {
2023-07-22 14:24:15 +00:00
fmt.Println(utils.LangListYandex(langlist))
2023-07-22 14:20:21 +00:00
} else {
fmt.Println(utils.TranslateYandex(dest, source, query))
}
2023-07-23 06:02:48 +00:00
} else if engine == "mymemory" {
if langlist == "sl" {
fmt.Println(utils.LangListMyMemory(langlist))
} else if langlist == "tl" {
fmt.Println(utils.LangListMyMemory(langlist))
} else {
fmt.Println(utils.TranslateMyMemory(dest, source, query))
}
2023-06-24 18:40:57 +00:00
} else if engine == "all" {
fmt.Println(utils.TranslateAll(dest, source, query))
} else {
if langlist == "sl" {
fmt.Println(utils.LangListGoogle(langlist))
} else if langlist == "tl" {
fmt.Println(utils.LangListGoogle(langlist))
} else {
fmt.Println(utils.TranslateGoogle(dest, source, query))
}
}
},
}
func init() {
rootCmd.AddCommand(translateCmd)
translateCmd.Flags().StringVarP(&engine, "engine", "e", "", "The source SimplyTranslate will listen to. Defaults to 3000, and overrides the SIMPLYTRANSLATE_source environment variable.")
translateCmd.Flags().StringVarP(&source, "source", "s", "", "The source SimplyTranslate will listen to. Defaults to 3000, and overrides the SIMPLYTRANSLATE_source environment variable.")
translateCmd.Flags().StringVarP(&dest, "dest", "t", "", "The dest SimplyTranslate will listen to. Defaults to 3000, and overrides the SIMPLYTRANSLATE_dest environment variable.")
translateCmd.Flags().StringVarP(&query, "query", "q", "", "The query SimplyTranslate will listen to. Defaults to 3000, and overrides the SIMPLYTRANSLATE_query environment variable.")
translateCmd.Flags().StringVarP(&langlist, "langlist", "l", "", "The query SimplyTranslate will listen to. Defaults to 3000, and overrides the SIMPLYTRANSLATE_query environment variable.")
engine = translateCmd.Flag("engine").Value.String()
dest = translateCmd.Flag("dest").Value.String()
source = translateCmd.Flag("source").Value.String()
query = translateCmd.Flag("query").Value.String()
langlist = translateCmd.Flag("query").Value.String()
}