mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2024-11-16 13:42:21 +08:00
fix: translation results may not be returned
This commit is contained in:
parent
f75bfc20f7
commit
7b97e65ec7
29
main.go
29
main.go
|
@ -2,7 +2,7 @@
|
||||||
* @Author: Vincent Yang
|
* @Author: Vincent Yang
|
||||||
* @Date: 2023-07-01 21:45:34
|
* @Date: 2023-07-01 21:45:34
|
||||||
* @LastEditors: Vincent Yang
|
* @LastEditors: Vincent Yang
|
||||||
* @LastEditTime: 2024-03-20 16:39:58
|
* @LastEditTime: 2024-04-09 03:02:08
|
||||||
* @FilePath: /DeepLX/main.go
|
* @FilePath: /DeepLX/main.go
|
||||||
* @Telegram: https://t.me/missuo
|
* @Telegram: https://t.me/missuo
|
||||||
* @GitHub: https://github.com/missuo
|
* @GitHub: https://github.com/missuo
|
||||||
|
@ -314,16 +314,23 @@ func translateByDeepLX(sourceLang string, targetLang string, translateText strin
|
||||||
alternatives = append(alternatives, value.Get("text").String())
|
alternatives = append(alternatives, value.Get("text").String())
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
return DeepLXTranslationResult{
|
if res.Get("result.texts.0.text").String() == "" {
|
||||||
Code: http.StatusOK,
|
return DeepLXTranslationResult{
|
||||||
ID: id,
|
Code: http.StatusServiceUnavailable,
|
||||||
Message: "Success",
|
Message: "Translation failed, API returns an empty result.",
|
||||||
Data: res.Get("result.texts.0.text").String(),
|
}, nil
|
||||||
Alternatives: alternatives,
|
} else {
|
||||||
SourceLang: sourceLang,
|
return DeepLXTranslationResult{
|
||||||
TargetLang: targetLang,
|
Code: http.StatusOK,
|
||||||
Method: "Free",
|
ID: id,
|
||||||
}, nil
|
Message: "Success",
|
||||||
|
Data: res.Get("result.texts.0.text").String(),
|
||||||
|
Alternatives: alternatives,
|
||||||
|
SourceLang: sourceLang,
|
||||||
|
TargetLang: targetLang,
|
||||||
|
Method: "Free",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return DeepLXTranslationResult{
|
return DeepLXTranslationResult{
|
||||||
Code: http.StatusServiceUnavailable,
|
Code: http.StatusServiceUnavailable,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user