Search in sources :

Example 26 with Language

use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.

the class ProjectSettingTMPage method checkDbHashMatch.

/**
	 * 需要调用Database模块 检查当前项目在库中是否有语言对的匹配
	 * @param dbModel
	 *            数据库信息;
	 */
public void checkDbHashMatch(DatabaseModelBean dbModel) {
    Language srcLang = super.projectInfoBean.getSourceLang();
    DBOperator dbOp = DatabaseService.getDBOperator(dbModel.toDbMetaData());
    if (null == dbOp) {
        return;
    }
    try {
        if (dbOp != null) {
            dbOp.start();
            dbModel.setHasMatch(dbOp.checkHasMatchs(srcLang.getCode(), "M"));
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        dbModel.setHasMatch(false);
    } finally {
        if (dbOp != null) {
            try {
                if (dbOp != null) {
                    dbOp.end();
                }
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Example 27 with Language

use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.

the class MatchViewPart method getTuInfoBean.

private TransUnitInfo2TranslationBean getTuInfoBean(TransUnitBean transUnit, XLFHandler handler, String rowId) {
    String srcFullText = transUnit.getSrcContent();
    String srcPureText = transUnit.getSrcText();
    if ("".equals(srcFullText.trim()) || "".equals(srcPureText.trim())) {
        return null;
    }
    sourceColunmCellRenderer.setTuSrcText(srcFullText);
    String srcLanguage = transUnit.getSrcLang();
    String tgtLanguage = transUnit.getTgtLang();
    tgtLanguage = handler.getNatTableColumnName().get("target");
    Language srcLang = LocaleService.getLanguageConfiger().getLanguageByCode(srcLanguage);
    Language tgtLang = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLanguage);
    if (srcLang.isBidi() || tgtLang.isBidi()) {
        gridTable.setOrientation(SWT.RIGHT_TO_LEFT);
    } else {
        gridTable.setOrientation(SWT.LEFT_TO_RIGHT);
    }
    TransUnitInfo2TranslationBean tuInfoBean = new TransUnitInfo2TranslationBean();
    tuInfoBean.setSrcFullText(srcFullText);
    tuInfoBean.setSrcPureText(srcPureText);
    tuInfoBean.setSrcLanguage(srcLanguage);
    tuInfoBean.setTgtLangugage(tgtLanguage);
    int contextSize = tmMatcher.getContextSize();
    if (contextSize != 0) {
        Map<String, String> context = handler.getTransUnitContext(rowId, contextSize);
        tuInfoBean.setPreContext(context.get("x-preContext"));
        tuInfoBean.setNextContext(context.get("x-nextContext"));
    } else {
        tuInfoBean.setPreContext("");
        tuInfoBean.setNextContext("");
    }
    return tuInfoBean;
}
Also used : Language(net.heartsome.cat.common.locale.Language) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean) Point(org.eclipse.swt.graphics.Point)

Example 28 with Language

use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.

the class ProjectConfiger method getSourceLanguage.

/**
	 * 获取项目源语言
	 * @return 返加null或Language,如果是null表示没有获取到项目的源语言;
	 * @throws XPathParseException
	 * @throws NavException
	 * @throws XPathEvalException
	 */
public Language getSourceLanguage() throws XPathParseException, XPathEvalException, NavException {
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    ap.selectXPath("/projectDescription/hs/language/source");
    if (ap.evalXPath() != -1) {
        String code = vu.getCurrentElementAttribut("code", "");
        String name = vu.getElementContent();
        String image = vu.getCurrentElementAttribut("image", "");
        String isBidi = vu.getCurrentElementAttribut("isbidi", "No");
        return new Language(code, name, image, isBidi.equals("NO") ? false : true);
    }
    return null;
}
Also used : Language(net.heartsome.cat.common.locale.Language) AutoPilot(com.ximpleware.AutoPilot)

Example 29 with Language

use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.

the class LanguageLabelProvider method getImage.

public Image getImage(Object element) {
    if (element instanceof Language) {
        Language lang = (Language) element;
        String code = lang.getCode();
        String imagePath = lang.getImagePath();
        if (imagePath != null && !imagePath.equals("")) {
            ImageDescriptor imageDesc = Activator.getImageDescriptor(imagePath);
            if (imageDesc != null) {
                ImageData data = imageDesc.getImageData().scaledTo(16, 12);
                Image image = new Image(Display.getDefault(), data);
                // 销毁原来的图片
                Image im = imageCache.put(code, image);
                if (im != null && !im.isDisposed()) {
                    im.dispose();
                }
                return image;
            }
        }
    }
    return null;
}
Also used : Language(net.heartsome.cat.common.locale.Language) ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image)

Example 30 with Language

use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.

the class NewProjectWizard method initProjectConfig.

/**
	 * 构建项目配置信息
	 * @param project
	 *            ;
	 * @throws CoreException
	 */
private void initProjectConfig(final IProject project, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    final IProgressMonitor sMonitor = monitor;
    sMonitor.beginTask(Messages.getString("wizard.NewProjectWizard.task2"), 3);
    sMonitor.worked(1);
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            ProjectInfoBean bean = new ProjectInfoBean();
            bean.setProjectName(project.getName());
            bean.setMapField(firstPage.getFieldMap());
            bean.setMapAttr(firstPage.getAttributeMap());
            bean.setSourceLang(secondPage.getSrcLanguage());
            bean.setTargetLang(secondPage.getTargetlanguage());
            for (AbstractNewProjectWizardPage extensionPage : extensionPages) {
                if (extensionPage.getPageType().equals("TM")) {
                    bean.setTmDb(extensionPage.getSelectedDatabase());
                } else if (extensionPage.getPageType().equals("TB")) {
                    bean.setTbDb(extensionPage.getSelectedDatabase());
                }
            }
            sMonitor.worked(1);
            ProjectConfiger projCfg = ProjectConfigerFactory.getProjectConfiger(project);
            sMonitor.worked(1);
            projCfg.updateProjectConfig(bean);
            // 记住当前语言信息
            IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
            ps.setValue(IPreferenceConstants.NEW_PROJECT_SRC_LANG, bean.getSourceLang().getCode());
            List<Language> targetLangList = bean.getTargetLang();
            StringBuffer bf = new StringBuffer();
            for (Language lang : targetLangList) {
                bf.append(lang.getCode());
                bf.append(",");
            }
            ps.setValue(IPreferenceConstants.NEW_PROJECT_TGT_LANG, bf.substring(0, bf.lastIndexOf(",")));
            if (sMonitor.isCanceled()) {
                try {
                    project.delete(true, sMonitor);
                } catch (CoreException e) {
                    logger.error("", e);
                }
                throw new OperationCanceledException();
            }
        }
    });
    sMonitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AbstractNewProjectWizardPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractNewProjectWizardPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) Language(net.heartsome.cat.common.locale.Language) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) List(java.util.List) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

Language (net.heartsome.cat.common.locale.Language)31 ArrayList (java.util.ArrayList)10 AutoPilot (com.ximpleware.AutoPilot)6 NavException (com.ximpleware.NavException)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 XPathEvalException (com.ximpleware.XPathEvalException)4 XPathParseException (com.ximpleware.XPathParseException)4 File (java.io.File)4 IOException (java.io.IOException)4 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)4 CoreException (org.eclipse.core.runtime.CoreException)4 GridData (org.eclipse.swt.layout.GridData)4 VTDGen (com.ximpleware.VTDGen)3 VTDNav (com.ximpleware.VTDNav)3 List (java.util.List)3 LanguageLabelProvider (net.heartsome.cat.ts.ui.composite.LanguageLabelProvider)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)3 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)3 XMLModifier (com.ximpleware.XMLModifier)2 FileOutputStream (java.io.FileOutputStream)2