From e6f60ae68f372736420cc71112dc08b4bfb2d21c Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Wed, 30 Aug 2023 15:13:34 +0530 Subject: [PATCH] add support for changing libretransl. instance --- TODO.md | 5 +---- utils/autodetect.go | 4 +++- utils/engines.go | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 877bfd2..8d87b1e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,9 @@ # TODO - Create a web interface -- Make CLI usable +- Interactive/Step-by-step CLI - CI/CD - Support for disabling engines - Ability for user to choose engines they want to use -- Fix DDG -- Support for changing LibreTranslate instance -- Add actual explanations for CLI arguments - Proper Error handling for requests.go - Tell which language Detect Language chose -- Only support for deepl and google is pending - Finish simplytranslate-py compatible API for translations diff --git a/utils/autodetect.go b/utils/autodetect.go index 8c086c9..79b891b 100644 --- a/utils/autodetect.go +++ b/utils/autodetect.go @@ -1,5 +1,7 @@ package utils +import "os" + func AutoDetectWatson(query string) (string, error) { json := []byte(`{"text":"` + query + `"}`) watsonOut := PostRequest("https://www.ibm.com/demos/live/watson-language-translator/api/translate/detect", json) @@ -10,7 +12,7 @@ func AutoDetectWatson(query string) (string, error) { func AutoDetectLibreTranslate(query string) (string, error) { json := []byte(`{"q":"` + query + `"}`) - libreTranslateOut := PostRequest("https://translate.argosopentech.com/detect", json) + libreTranslateOut := PostRequest(os.Getenv("MOZHI_LIBRETRANSLATE_URL")+"/detect", json) gjsonArr := libreTranslateOut.Get("0.language").Array() answer := gjsonArr[0].String() return answer, nil diff --git a/utils/engines.go b/utils/engines.go index 44ce3e7..95bc812 100644 --- a/utils/engines.go +++ b/utils/engines.go @@ -129,7 +129,7 @@ func TranslateLibreTranslate(to string, from string, query string) (LangOut, err } json := []byte(`{"q":"` + query + `","source":"` + from + `","target":"` + to + `"}`) // TODO: Make it configurable - libreTranslateOut := PostRequest("https://translate.argosopentech.com/translate", json) + libreTranslateOut := PostRequest(os.Getenv("MOZHI_LIBRETRANSLATE_URL")+"/translate", json) gjsonArr := libreTranslateOut.Get("translatedText").Array() var langout LangOut langout.OutputText = gjsonArr[0].String()