add support for changing libretransl. instance

This commit is contained in:
Arya 2023-08-30 15:13:34 +05:30
parent 0409b30960
commit e6f60ae68f
Signed by: arya
GPG Key ID: 842D12BDA50DF120
3 changed files with 5 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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()