mirror of
https://codeberg.org/aryak/mozhi
synced 2024-11-16 10:13:04 +05:30
give an error if someone tries to use libre without url set
This commit is contained in:
parent
e6f60ae68f
commit
0e2be0cd32
@ -54,13 +54,14 @@ 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)
|
||||
}
|
||||
fmt.Println("Source Language: " + data.SourceLang)
|
||||
fmt.Println("Target Language: " + data.TargetLang)
|
||||
}
|
||||
fmt.Println("Translated Text: " + data.OutputText)
|
||||
if source == "auto" {
|
||||
fmt.Println("Detected Language: " + data.AutoDetect)
|
||||
}
|
||||
fmt.Println("Source Language: " + data.SourceLang)
|
||||
fmt.Println("Target Language: " + data.TargetLang)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user