Exemplo n.º 1
0
package net.heartsome.cat.te.tmxeditor.editor;
Exemplo n.º 2
0
  @Override
  public String startQA(
      final QAModel model,
      IProgressMonitor monitor,
      IFile iFile,
      QAXmlHandler xmlHandler,
      Map<String, String> tuMap) {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    hasError = false;
    isContinue = false;
    // 目标语言
    final String target_lan = tuMap.get("target_lan");

    // 若未配置该目标语言的词典,退出程序的执行
    if (nonSpellTarLangList.indexOf(target_lan) != -1) {
      return "";
    }

    String targetPureText = TextUtil.resetSpecialString(tuMap.get("tarPureText"));

    String lineNumber = tuMap.get("lineNumber");
    String langPair = tuMap.get("langPair");
    String iFileFullPath = tuMap.get("iFileFullPath");
    String rowId = tuMap.get("rowId");

    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(target_lan)) {
      nonSpellTarLangList.add(target_lan);
      if (!isHunspell) {
        Display.getDefault()
            .syncExec(
                new Runnable() {
                  public void run() {
                    String message = Messages.getString("qa.SpellQA.addTip1");
                    message = MessageFormat.format(message, new Object[] {target_lan});
                    isContinue =
                        MessageDialog.openConfirm(
                            model.getShell(), Messages.getString("qa.all.dialog.ok"), message);
                  }
                });

        if (!isContinue) {
          monitor.setCanceled(true);
        }
      }
      return "";
    }

    List<SingleWord> errorWords;
    if (isHunspell) {
      LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
      getSingleWords(targetPureText, wordList);
      errorWords = spelling.getErrorWords(null, wordList, target_lan);
    } else {
      LinkedList<SingleWord> wordList = new LinkedList<SingleWord>();
      getSingleWords(targetPureText, wordList);
      errorWords = spelling.getErrorWords(targetPureText, wordList, target_lan);
    }

    if (spelling.isError()) {
      return null;
    }

    // 开始输入结果
    if (errorWords == null || errorWords.size() == 0) {
      return "";
    }

    String errorTip = Messages.getString("qa.SpellQA.tip1");
    String qaType = Messages.getString("qa.all.qaItem.SpellQA");

    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(
            lineNumber,
            qaType,
            errorTip,
            iFileFullPath,
            langPair,
            rowId,
            tipLevel,
            QAConstant.QA_SPELL));
    String result = "";
    if (hasError && tipLevel == 0) {
      result = QAConstant.QA_SPELL;
    }
    return result;
  }