Skip to content

Commit

Permalink
fix: translation results may not be returned
Browse files Browse the repository at this point in the history
  • Loading branch information
missuo committed Apr 9, 2024
1 parent f75bfc2 commit 7b97e65
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Vincent Yang
* @Date: 2023-07-01 21:45:34
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-03-20 16:39:58
* @LastEditTime: 2024-04-09 03:02:08
* @FilePath: /DeepLX/main.go
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
Expand Down Expand Up @@ -314,16 +314,23 @@ func translateByDeepLX(sourceLang string, targetLang string, translateText strin
alternatives = append(alternatives, value.Get("text").String())
return true
})
return DeepLXTranslationResult{
Code: http.StatusOK,
ID: id,
Message: "Success",
Data: res.Get("result.texts.0.text").String(),
Alternatives: alternatives,
SourceLang: sourceLang,
TargetLang: targetLang,
Method: "Free",
}, nil
if res.Get("result.texts.0.text").String() == "" {
return DeepLXTranslationResult{
Code: http.StatusServiceUnavailable,
Message: "Translation failed, API returns an empty result.",
}, nil
} else {
return DeepLXTranslationResult{
Code: http.StatusOK,
ID: id,
Message: "Success",
Data: res.Get("result.texts.0.text").String(),
Alternatives: alternatives,
SourceLang: sourceLang,
TargetLang: targetLang,
Method: "Free",
}, nil
}
}
return DeepLXTranslationResult{
Code: http.StatusServiceUnavailable,
Expand Down

0 comments on commit 7b97e65

Please sign in to comment.