|
|
|
@ -78,21 +78,21 @@ public class YouDaoTranslationUtils { |
|
|
|
// 检查是否有错误
|
|
|
|
if (result.containsKey("errorCode") && result.getStr("errorCode").equals("0")) { |
|
|
|
log.error("有道翻译失败,错误码:{},错误信息:{}", result.getStr("errorCode"), result.getStr("errorMsg")); |
|
|
|
return result.getStr("errorMsg") == null ? "system error" : "system error:" + result.getStr("errorMsg"); |
|
|
|
return result.getStr("errorMsg") == null ? "有道翻译失败" : "有道翻译失败:" + result.getStr("errorMsg"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取翻译结果
|
|
|
|
JSONArray translationArray = result.getJSONArray("translation"); |
|
|
|
if (translationArray == null || translationArray.isEmpty()) { |
|
|
|
log.error("有道翻译结果为空"); |
|
|
|
return "result empty"; |
|
|
|
return "有道翻译结果为空"; |
|
|
|
} |
|
|
|
|
|
|
|
// 返回第一条翻译结果
|
|
|
|
return translationArray.getStr(0); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("有道翻译异常", e); |
|
|
|
return "translation unknown error"; |
|
|
|
return "有道翻译异常"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -154,21 +154,21 @@ public class YouDaoTranslationUtils { |
|
|
|
if (result.containsKey("errorCode") &&!result.getStr("errorCode").equals("0")) { |
|
|
|
System.out.println(result); |
|
|
|
log.error("有道翻译失败,错误码:{},错误信息:{}", result.getStr("errorCode"), result.getStr("errorMsg")); |
|
|
|
return result.getStr("errorMsg") == null ? "system error" : "system error:" + result.getStr("errorMsg"); |
|
|
|
return result.getStr("errorMsg") == null ? "有道翻译失败" : "有道翻译失败:" + result.getStr("errorMsg"); |
|
|
|
} |
|
|
|
System.out.println(result); |
|
|
|
// 获取翻译结果
|
|
|
|
JSONArray translationArray = result.getJSONArray("translation"); |
|
|
|
if (translationArray == null || translationArray.isEmpty()) { |
|
|
|
log.error("有道翻译结果为空"); |
|
|
|
return "result empty"; |
|
|
|
return "有道翻译结果为空"; |
|
|
|
} |
|
|
|
|
|
|
|
// 返回第一条翻译结果
|
|
|
|
return translationArray.getStr(0); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("有道翻译异常", e); |
|
|
|
return "translation unknown error"; |
|
|
|
return "有道翻译异常"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|