use of net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate 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;
}
use of net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate in project translationstudio8 by heartsome.
the class NonTranslationQA method startQA.
@Override
public String startQA(QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
return "";
}
hasError = false;
if (nonTransElementsMap == null) {
//非译元素库的操作类
NonTransElementOperate operater = new NonTransElementOperate();
//先打开库
operater.openNonTransDB();
//开始从非译元素库中获取相关信息
nonTransElementsMap = operater.getNonTransElements();
}
srcNonTransData = new LinkedList<String>();
tgtNonTransData = new LinkedList<String>();
//获取纯文本
String sourceText = tuDataBean.getSrcPureText();
String targetText = tuDataBean.getTgtPureText();
String rowId = tuDataBean.getRowId();
srcLang = tuDataBean.getSrcLang();
tgtLang = tuDataBean.getTgtLang();
// UNDO 这里存在一个问题,就是web地址检查与ip地址检查的语句差不多,故存在会引起一个非译元素会同时被检查并多次提示。
for (int index = 0; index < nonTransElementsMap.size(); index++) {
NontransElementBean elementBean = nonTransElementsMap.get(index);
String elementContent = elementBean.getContent();
String elementRegular = elementBean.getRegular();
matchNontrans(sourceText, targetText, elementContent, elementRegular);
}
// UNDO 非译元素检查时,把数字也检查出来了
String lineNumber = tuDataBean.getLineNumber();
String fileName = tuDataBean.getFileName();
String qaTypeText = Messages.getString("qa.all.qaItem.NonTranslationQA");
//处理源文中的非译元素在译文中丢失的情况
if (srcNonTransData.size() > 0) {
String nonTransStr = "";
for (int index = 0; index < srcNonTransData.size(); index++) {
nonTransStr += "'" + srcNonTransData.get(index) + "', ";
}
nonTransStr = nonTransStr.substring(0, nonTransStr.length() - 2);
// String errorTip = MessageFormat.format(Messages.getString("qa.NonTranslationQA.tip1"), nonTransStr);
hasError = true;
}
//处理译文中的非译元素在源文中丢失的情况
if (tgtNonTransData.size() > 0) {
String nonTransStr = "";
for (int index = 0; index < tgtNonTransData.size(); index++) {
nonTransStr += "'" + tgtNonTransData.get(index) + "', ";
}
nonTransStr = nonTransStr.substring(0, nonTransStr.length() - 2);
// String errorTip = MessageFormat.format(Messages.getString("qa.NonTranslationQA.tip2"), nonTransStr);
hasError = true;
}
if (hasError) {
super.printQAResult(new QAResultBean(level, QAConstant.QA_NONTRANSLATION, qaTypeText, null, fileName, lineNumber, sourceText, targetText, rowId));
}
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_NONTRANSLATION;
}
return result;
}
use of net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate in project translationstudio8 by heartsome.
the class NonTranslationQAPage method initValue.
/**
* 初始化相关数据
*/
public void initValue() {
operate = new NonTransElementOperate();
operate.openNonTransDB();
internalElementList = QAModel.getInterNonTransElements();
defaultTipList.add(new NontransElementBean(null, Messages.getString("qa.preference.NonTranslationQAPage.addInterElement"), null, null));
dataList = operate.getNonTransElements();
}
use of net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate in project translationstudio8 by heartsome.
the class RealTimeSpellCheck method loadParams.
private void loadParams() {
isHunspell = preferenceStore.getBoolean(QAConstant.QA_PREF_isHunspell);
isRealTimeSpell = preferenceStore.getBoolean(QAConstant.QA_PREF_realTimeSpell);
ignoreNontrans = preferenceStore.getBoolean(QAConstant.QA_PREF_ignoreNontrans);
ignoreDigitalFirst = preferenceStore.getBoolean(QAConstant.QA_PREF_ignoreDigitalFirst);
ignoreUpperCaseFirst = preferenceStore.getBoolean(QAConstant.QA_PREF_ignoreUpperCaseFirst);
ignoreAllUpperCase = preferenceStore.getBoolean(QAConstant.QA_PREF_ignoreAllUpperCase);
if (isHunspell) {
if (ignoreNontrans) {
nontransOper = new NonTransElementOperate();
nontransOper.openNonTransDB();
}
spelling = new Hunspell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
} else {
spelling = new AspellChecker();
}
}
Aggregations