diff --git a/.gitignore b/.gitignore index 627dea1..43fe45d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ obj/ *.user .DS_Store +publish/* \ No newline at end of file diff --git a/STranslateDLL/LocalMode.cs b/STranslateDLL/LocalMode.cs index cc3af3c..18d7007 100644 --- a/STranslateDLL/LocalMode.cs +++ b/STranslateDLL/LocalMode.cs @@ -69,8 +69,16 @@ public static class LocalMode Code = 500, Data = "Error: No translation result" }); - else - data = jsonArray.Aggregate(data, (current, item) => current + item?["beams"]?[0]?["sentences"]?[0]?["text"]); + foreach (var item in jsonArray) + { + var beams = item?["beams"]; + if (beams is not JsonArray { Count: > 0 } beamsArray) continue; + var sentences = beamsArray[0]?["sentences"]; + if (sentences is JsonArray { Count: > 0 } sentencesArray) + { + data += sentencesArray[0]?["text"]?.ToString() ?? ""; + } + } // data = jNode?["result"]?["translations"]?[0]?["beams"]?[0]?["sentences"]?[0]?["text"]?.ToString(); var errorMsg = jNode?["error"]?["message"]?.ToString(); var detailsMsg = jNode?["error"]?["data"]?["what"]?.ToString(); diff --git a/STranslateDLLTests/LocalModeTests.cs b/STranslateDLLTests/LocalModeTests.cs index d2bc2a9..16401e9 100644 --- a/STranslateDLLTests/LocalModeTests.cs +++ b/STranslateDLLTests/LocalModeTests.cs @@ -13,7 +13,7 @@ public class LocalModeTests(ITestOutputHelper testOutputHelper) try { var cts = new CancellationTokenSource(); - var ret = await LocalMode.ExecuteAsync("20241105版本说明:\\r\\n1. 修复STranslate本地服务翻译失败的问题\\r\\n2. 添加生词本(欧路词典)\\r\\n3. 优化设置页面\\r\\n4. 优化查词显示效果\\r\\n5. 添加金山词霸、必应词典作为内置服务\\r\\n6. 添加EdgeTTS作为内置服务,TTS效果更佳\\r\\n7. 添加软件内TTS热键(参见设置-热键设置-软件热键列表)\\r\\n8. 启动时可选不显示通知\\r\\n9. 粘贴文本自动执行翻译\\r\\n---\\r\\n测试项:\\r\\n替换翻译及静默OCR使用鼠标样式作为执行中标记,如若执行结束导致鼠标未恢复,恳请反馈一下,恢复方式到设置中设置鼠标即可https://jingyan.baidu.com/article/6c67b1d6ddbced6686bb1e2c.html\\r\\n\\r\\n开发者个人样本比较少,不知道是否存在不可控因素,这两天大家如果没有问题反馈就发正式版本", "ZH", "EN", cts.Token); + var ret = await LocalMode.ExecuteAsync("20241105 version description: 1. fix the problem of translation failure of STranslate local service 2. add vocabulary book (Oulu Dictionary) 3. optimize the setting page 4. optimize the display effect of word searching 5. add Kingsoft Wordsmith and Bing Dictionary as built-in service 6. add EdgeTTS as built-in service, the effect of TTS will be better 7. add the TTS hotkeys in the software (see Settings - Hotkey Settings - Software Hotkey List) 8.Add TTS hotkeys in the software (see Settings - Hotkey Settings - Software Hotkey List) 8. Optional not to show notification at startup 9. Paste text to execute translation automatically --Test: Replacement Translation and Silent OCR use the mouse style as a marker in the execution, such as the end of the execution caused by the mouse has not been restored, please give us feedback on the restoration of the mouse can be set up in the settings of the recovery method to set up the mouse https://jingyan.baidu.com/article/6c67b1d6ddbced6686bb1e2c.html The developer's personal samples are relatively small, I do not know whether there are uncontrollable factors, the next two days, if you do not have any problems with the feedback will be sent to the official version!", "EN", "ZH", cts.Token); testOutputHelper.WriteLine(ret); } catch (Exception ex)