Search in sources :

Example 1 with NonTransElementOperate

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;
}
Also used : NonTransElementOperate(net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate) AspellChecker(net.heartsome.cat.ts.ui.qa.spell.AspellChecker) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) SingleWord(net.heartsome.cat.ts.core.bean.SingleWord) Hunspell(net.heartsome.cat.ts.ui.qa.spell.Hunspell) LinkedList(java.util.LinkedList)

Example 2 with NonTransElementOperate

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;
}
Also used : NonTransElementOperate(net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate) NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean) QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean)

Example 3 with NonTransElementOperate

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();
}
Also used : NonTransElementOperate(net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate) NontransElementBean(net.heartsome.cat.ts.ui.qa.model.NontransElementBean)

Example 4 with NonTransElementOperate

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();
    }
}
Also used : NonTransElementOperate(net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate)

Aggregations

NonTransElementOperate (net.heartsome.cat.ts.ui.qa.nonTransElement.NonTransElementOperate)4 NontransElementBean (net.heartsome.cat.ts.ui.qa.model.NontransElementBean)2 QAResultBean (net.heartsome.cat.ts.ui.qa.model.QAResultBean)2 LinkedList (java.util.LinkedList)1 SingleWord (net.heartsome.cat.ts.core.bean.SingleWord)1 AspellChecker (net.heartsome.cat.ts.ui.qa.spell.AspellChecker)1 Hunspell (net.heartsome.cat.ts.ui.qa.spell.Hunspell)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1