mirror of
https://codeberg.org/aryak/mozhi
synced 2024-12-23 00:19:51 +05:30
give an error if someone tries to use libre without url set
This commit is contained in:
parent
e6f60ae68f
commit
0e2be0cd32
@ -54,7 +54,7 @@ var translateCmd = &cobra.Command{
|
|||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
} else {
|
||||||
fmt.Println("Translated Text: " + data.OutputText)
|
fmt.Println("Translated Text: " + data.OutputText)
|
||||||
if source == "auto" {
|
if source == "auto" {
|
||||||
fmt.Println("Detected Language: " + data.AutoDetect)
|
fmt.Println("Detected Language: " + data.AutoDetect)
|
||||||
@ -63,6 +63,7 @@ var translateCmd = &cobra.Command{
|
|||||||
fmt.Println("Target Language: " + data.TargetLang)
|
fmt.Println("Target Language: " + data.TargetLang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type List struct {
|
type List struct {
|
||||||
@ -24,6 +25,9 @@ func LangList(engine string, listType string) ([]List, error) {
|
|||||||
if engine == "google" {
|
if engine == "google" {
|
||||||
data = LangListGoogle(listType)
|
data = LangListGoogle(listType)
|
||||||
} else if engine == "libre" {
|
} 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)
|
data = LangListLibreTranslate(listType)
|
||||||
} else if engine == "reverso" {
|
} else if engine == "reverso" {
|
||||||
data = LangListReverso(listType)
|
data = LangListReverso(listType)
|
||||||
@ -50,6 +54,9 @@ func Translate(engine string, to string, from string, text string) (LangOut, err
|
|||||||
if engine == "google" {
|
if engine == "google" {
|
||||||
data, err = TranslateGoogle(to, from, text)
|
data, err = TranslateGoogle(to, from, text)
|
||||||
} else if engine == "libre" {
|
} 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)
|
data, err = TranslateLibreTranslate(to, from, text)
|
||||||
} else if engine == "reverso" {
|
} else if engine == "reverso" {
|
||||||
data, err = TranslateReverso(to, from, text)
|
data, err = TranslateReverso(to, from, text)
|
||||||
|
Loading…
Reference in New Issue
Block a user