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 +}