From c04b2bcf3a660856704b39373ef80929df3c43d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 12 Oct 2019 00:33:16 +0200 Subject: [PATCH] Identify langage if no language map is provided by user --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index d7d1e3a..c8ea35b 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "os" "strings" "./trans" + "./identify" "github.com/deanishe/awgo" "regexp" ) @@ -21,6 +22,9 @@ func main() { func run() { word, fromLang, toLang := parseProgramArgs(os.Args) + if fromLang == "" && toLang == "" { + fromLang, toLang = decideWhatLanguagesToUse(word) + } translations := trans.New(word, fromLang, toLang).Translate() for _, translation := range translations { @@ -52,3 +56,15 @@ func isTransLanguageSpecifier(arg string) bool { ok, _ := regexp.MatchString("(\\w{2})?:(\\w{2})?", os.Args[1]) return ok } + +func decideWhatLanguagesToUse(word string) (string, string) { + fromLang := identify.New(word).Identify() + toLang := map[string]string{ + "en": "hu", + "hu": "en", + }[fromLang] + if toLang == "" { + toLang = "en" + } + return fromLang, toLang +}