use of net.heartsome.cat.ts.ui.qa.spell.AspellChecker in project translationstudio8 by heartsome.
the class SpellQA method startQA.
@Override
public String startQA(final QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
return "";
}
if (monitor == null) {
monitor = new NullProgressMonitor();
}
hasError = false;
isContinue = false;
//目标语言
final String tgtLang = tuDataBean.getTgtLang();
//若未配置该目标语言的词典,退出程序的执行
if (nonSpellTarLangList.indexOf(tgtLang) != -1) {
return "";
}
String tgtPureText = TextUtil.resetSpecialString(tuDataBean.getTgtPureText());
String lineNumber = tuDataBean.getLineNumber();
String rowId = tuDataBean.getRowId();
if (spelling == null) {
if (isHunspell) {
spelling = new Hunspell(model.getShell());
if (ignoreNontrans) {
nontransOper = new NonTransElementOperate();
nontransOper.openNonTransDB();
}
} else {
spelling = new AspellChecker();
}
}
// 若拼写检查器错误,或者出错,返回 null
if (spelling == null || spelling.isError()) {
return null;
}
//如果该拼写检查实例为空,退出执行,并且下次遇到相同目标语言不再检查
if (!spelling.checkLangAvailable(tgtLang)) {
nonSpellTarLangList.add(tgtLang);
if (!isHunspell) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
String message = Messages.getString("qa.SpellQA.addTip1");
message = MessageFormat.format(message, new Object[] { tgtLang });
isContinue = MessageDialog.openConfirm(model.getShell(), Messages.getString("qa.all.dialog.confirm"), message);
}
});
if (!isContinue) {
monitor.setCanceled(true);
}
}
return "";
}
List<SingleWord> errorWords;
if (isHunspell) {
LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
getSingleWords(tgtPureText, wordList);
errorWords = spelling.getErrorWords(null, wordList, tgtLang);
} else {
LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
getSingleWords(tgtPureText, wordList);
errorWords = spelling.getErrorWords(tgtPureText, wordList, tgtLang);
}
if (spelling.isError()) {
return null;
}
//开始输入结果
if (errorWords == null || errorWords.size() == 0) {
return "";
}
String qaTypeText = Messages.getString("qa.all.qaItem.SpellQA");
// String errorTip = Messages.getString("qa.SpellQA.tip1");
// for (int i = 0; i < errorWords.size(); i++) {
// errorTip += "'" + errorWords.get(i).getPureWord() + "' 、";
// }
// errorTip = errorTip.substring(0, errorTip.length() - 1);
// errorTip += Messages.getString("qa.SpellQA.tip2");
hasError = true;
super.printQAResult(new QAResultBean(level, QAConstant.QA_SPELL, qaTypeText, null, tuDataBean.getFileName(), lineNumber, tuDataBean.getSrcContent(), tuDataBean.getTgtContent(), rowId));
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_SPELL;
}
return result;
}
Aggregations