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 {
|
if len(data) <= 0 {
|
||||||
return nil, errors.New("Translation not found")
|
return nil, errors.New("Translation not found")
|
||||||
}
|
}
|
||||||
|
// If responseData is nil, then suppose the translation pair is not available
|
||||||
switch res.StatusCode {
|
if data["responseData"] == nil {
|
||||||
case 200:
|
return nil, errors.New(fmt.Sprintf("%s does not support translate from %s to %s.",
|
||||||
translation.TEXT = fmt.Sprintf("%v",
|
t.GetEngineName(),
|
||||||
data["responseData"].(map[string]interface{})["translatedText"])
|
t.GetSrcLang(),
|
||||||
default:
|
t.GetDstLang(),
|
||||||
return nil, errors.New(
|
))
|
||||||
fmt.Sprintf("%s does not support translate from %s to %s.\nSee available pair on %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
|
return translation, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user