fix: 修复当前文本翻译完成后,再次加载pbo后,无法开始翻译任务的问题

This commit is contained in:
octopus_yan 2024-11-22 00:01:54 +08:00
parent 0c9052216b
commit c6f0268ff5
2 changed files with 5 additions and 3 deletions

View File

@ -518,7 +518,7 @@ public class PBOUtil {
* @param str 需要判断的字符串
* @return 是否含有中文
*/
private static boolean containsChinese(String str) {
public static boolean containsChinese(String str) {
return Pattern.compile("[\u4e00-\u9fa5]").matcher(str).find();
}
}

View File

@ -10,6 +10,7 @@ import cn.octopusyan.dmt.task.UnpackTask;
import cn.octopusyan.dmt.task.listener.DefaultTaskListener;
import cn.octopusyan.dmt.translate.DelayWord;
import cn.octopusyan.dmt.translate.TranslateUtil;
import cn.octopusyan.dmt.utils.PBOUtil;
import cn.octopusyan.dmt.view.ConsoleLog;
import cn.octopusyan.dmt.view.alert.AlertUtil;
import javafx.application.Platform;
@ -18,7 +19,6 @@ import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.concurrent.Worker;
import javafx.scene.control.ProgressIndicator;
import org.apache.commons.lang3.StringUtils;
import org.kordamp.ikonli.feather.Feather;
import org.kordamp.ikonli.javafx.FontIcon;
@ -107,9 +107,11 @@ public class MainViewModel extends BaseViewModel<MainController> {
if (wordItems.isEmpty()) return;
if (translateTask == null) {
List<WordItem> words = wordItems.stream().filter(item -> StringUtils.isEmpty(item.getChinese())).toList();
List<WordItem> words = wordItems.stream().filter(item -> !PBOUtil.containsChinese(item.getChinese())).toList();
delayQueue = TranslateUtil.getDelayQueue(words);
translateTask = createTask();
translateTask.execute();
return;
}
if (!translateTask.isRunning()) {