give an error if someone tries to use libre without url set

This commit is contained in:
Arya 2023-08-30 15:26:20 +05:30
parent e6f60ae68f
commit 0e2be0cd32
Signed by: arya
GPG Key ID: 842D12BDA50DF120
2 changed files with 14 additions and 6 deletions

View File

@ -54,7 +54,7 @@ var translateCmd = &cobra.Command{
} else {
if err != nil {
fmt.Println(err)
}
} else {
fmt.Println("Translated Text: " + data.OutputText)
if source == "auto" {
fmt.Println("Detected Language: " + data.AutoDetect)
@ -63,6 +63,7 @@ var translateCmd = &cobra.Command{
fmt.Println("Target Language: " + data.TargetLang)
}
}
}
},
}

View File

@ -2,6 +2,7 @@ package utils
import (
"errors"
"os"
)
type List struct {
@ -24,6 +25,9 @@ func LangList(engine string, listType string) ([]List, error) {
if engine == "google" {
data = LangListGoogle(listType)
} else if engine == "libre" {
if os.Getenv("MOZHI_LIBRETRANSLATE_URL") == "" {
return []List{}, errors.New("Please set MOZHI_LIBRETRANSLATE_URL if you want to use libretranslate. Example: MOZHI_LIBRETRANSLATE_URL=https://lt.psf.lt")
}
data = LangListLibreTranslate(listType)
} else if engine == "reverso" {
data = LangListReverso(listType)
@ -50,6 +54,9 @@ func Translate(engine string, to string, from string, text string) (LangOut, err
if engine == "google" {
data, err = TranslateGoogle(to, from, text)
} else if engine == "libre" {
if os.Getenv("MOZHI_LIBRETRANSLATE_URL") == "" {
return LangOut{}, errors.New("Please set MOZHI_LIBRETRANSLATE_URL if you want to use libretranslate. Example: MOZHI_LIBRETRANSLATE_URL=https://lt.psf.lt")
}
data, err = TranslateLibreTranslate(to, from, text)
} else if engine == "reverso" {
data, err = TranslateReverso(to, from, text)