Browse Source

翻译方法优化

master
La123123 1 week ago
parent
commit
fb9bfdff96
  1. 43
      im-platform/src/main/java/com/bx/implatform/controller/LoginController.java

43
im-platform/src/main/java/com/bx/implatform/controller/LoginController.java

@ -99,41 +99,22 @@ public class LoginController {
str = str.replace("\n", ""); str = str.replace("\n", "");
//翻译目标国家 //翻译目标国家
String country = jsonObject.getStr("country"); String country = jsonObject.getStr("country","zh");
String trans = ""; String trans = "";
//如果代理有配置,则使用代理的配置 //如果代理有配置,则使用代理的配置
String translateType = settingService.translateType(); String translateType = settingService.translateType();
switch (translateType) { trans = switch (translateType) {
case "0"://默认使用系统自带的百度翻译 case "0" ->//默认使用系统自带的百度翻译
if (country == null || country.isEmpty()) { baiduTranslationUtils.translate(str, country);
trans = baiduTranslationUtils.translate(str, "zh"); case "1" ->//使用百度翻译
} else { baiduTranslationUtils.translateByAgentConfiguration(str, country);
trans = baiduTranslationUtils.translate(str, country); case "2" ->//使用有道翻译
} youDaoTranslationUtils.translateByAgentConfiguration(str, country);
break; case "3" ->//使用谷歌翻译
case "1": googleTranslationUtils.translateByAgentConfiguration(str, country);
if (country == null || country.isEmpty()) { default -> trans;
trans = baiduTranslationUtils.translateByAgentConfiguration(str, "zh"); };
} else {
trans = baiduTranslationUtils.translateByAgentConfiguration(str, country);
}
break;
case "2":
if (country == null || country.isEmpty()) {
trans = youDaoTranslationUtils.translateByAgentConfiguration(str, "zh");
} else {
trans = youDaoTranslationUtils.translateByAgentConfiguration(str, country);
}
break;
case "3":
if (country == null || country.isEmpty()) {
trans = googleTranslationUtils.translateByAgentConfiguration(str, "zh");
} else {
trans = googleTranslationUtils.translateByAgentConfiguration(str, country);
}
break;
}
return ResultUtils.success(trans,"success"); return ResultUtils.success(trans,"success");
} }

Loading…
Cancel
Save