Skip to content

Commit 8f89e66

Browse files
committed
优化火山翻译
1 parent 9f03421 commit 8f89e66

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Mikoto/Helpers/Text/TextRepair.cs

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public static partial class TextRepair
1616

1717
public static string? RegexReplacement { get; set; }
1818
public static string? RegexPattern { get; set; }
19+
/// <summary>
20+
/// 检测重复句子时使用的最小字符数。
21+
/// 若字符串末尾存在长度不少于该值的重复部分,则视为重复句子。
22+
/// </summary>
1923
public static int SentenceRepeatFindCharNum { get; set; }
2024
public static int SingleWordRepeatTimes { get; set; }
2125

Mikoto/Translators/Implementations/VolcanoTranslator.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,19 @@ private static string BuildRequestJson(string[] text, string sourceLanguage, str
146146
string? result = jsonNode?["TranslationList"]?[0]?["Translation"]?.GetValue<string>();
147147
if (result == null)
148148
{
149-
errorInfo = "ErrorCodeN: " + jsonNode!["ResponseMetadata"]!["Error"]!["CodeN"]!.GetValue<int>() + Environment.NewLine
150-
+ "ErrorCode: " + jsonNode["ResponseMetadata"]!["Error"]!["Code"]!.GetValue<string>() + Environment.NewLine
151-
+ "ErrorMessage: " + jsonNode["ResponseMetadata"]!["Error"]!["Message"]!.GetValue<string>();
149+
// 提取错误信息
150+
var errorNode = jsonNode?["ResponseMetadata"]?["Error"];
151+
if (errorNode != null)
152+
{
153+
int? errorCodeN = errorNode["CodeN"]?.GetValue<int>();
154+
string? errorCode = errorNode["Code"]?.GetValue<string>();
155+
string? errorMessage = errorNode["Message"]?.GetValue<string>();
156+
157+
errorInfo = $"ErrorCodeN: {errorCodeN}{Environment.NewLine}" +
158+
$"ErrorCode: {errorCode}{Environment.NewLine}" +
159+
$"ErrorMessage: {errorMessage}";
160+
}
161+
152162
return null;
153163
}
154164
else

0 commit comments

Comments
 (0)