mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-16 15:50:52 -07:00
refactor: check Apertium translate with responseData instead of StatusCode
This commit is contained in:
parent
ecdebc39ad
commit
24cadc4072
@ -58,21 +58,18 @@ func (t *Translator) Translate(message string) (translation *core.Translation, e
|
||||
if len(data) <= 0 {
|
||||
return nil, errors.New("Translation not found")
|
||||
}
|
||||
|
||||
switch res.StatusCode {
|
||||
case 200:
|
||||
translation.TEXT = fmt.Sprintf("%v",
|
||||
data["responseData"].(map[string]interface{})["translatedText"])
|
||||
default:
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf("%s does not support translate from %s to %s.\nSee available pair on %s",
|
||||
// If responseData is nil, then suppose the translation pair is not available
|
||||
if data["responseData"] == nil {
|
||||
return nil, errors.New(fmt.Sprintf("%s does not support translate from %s to %s.",
|
||||
t.GetEngineName(),
|
||||
t.GetSrcLang(),
|
||||
t.GetDstLang(),
|
||||
"https://www.apertium.org/",
|
||||
))
|
||||
}
|
||||
|
||||
translation.TEXT = fmt.Sprintf("%v",
|
||||
data["responseData"].(map[string]interface{})["translatedText"])
|
||||
|
||||
return translation, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user