Search in sources :

Example 11 with Language

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

the class AddTermToTBDialog method initProperty.

/**
	 * 初始化各个控件的值 ;
	 */
public void initProperty() {
    if (srcText != null && !srcText.equals("")) {
        txtSrc.setText(srcText);
        txtSrc.setSelection(0, srcText.length());
        txtSrc.setFocus();
    }
    if (tgtText != null && !tgtText.equals("")) {
        txtTgt.setText(tgtText);
        txtTgt.setSelection(0, tgtText.length());
        txtTgt.setFocus();
    }
    if (getPropertyValue() != null) {
        txtProperty.setText(getPropertyValue());
    }
    ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
    List<Language> rsLstSrcLangs = new ArrayList<Language>();
    List<Language> rsLstTgtLangs = null;
    try {
        rsLstSrcLangs.add(projectConfig.getSourceLanguage());
        rsLstTgtLangs = projectConfig.getTargetlanguages();
    } catch (XPathParseException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    } catch (NavException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    } catch (XPathEvalException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    }
    ArrayList<String> lstTgtLangs = new ArrayList<String>();
    if (rsLstTgtLangs != null) {
        for (Language lang : rsLstTgtLangs) {
            lstTgtLangs.add(lang.getCode());
        }
    }
    cmbSrcLang.setLabelProvider(new LanguageLabelProvider());
    cmbSrcLang.setInput(rsLstSrcLangs);
    cmbSrcLang.getTableCombo().select(0);
    cmbTgtLang.setLabelProvider(new LanguageLabelProvider());
    cmbTgtLang.setInput(rsLstTgtLangs);
    if (tgtLang != null) {
        cmbTgtLang.getTableCombo().select(lstTgtLangs.indexOf(tgtLang));
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) ArrayList(java.util.ArrayList) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException)

Example 12 with Language

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

the class XLFValidator method getProjectLang.

/**
	 * 获取 iFile 所在项目的源语言与目标语言
	 * @param iFile
	 * @return 数组中的第一个值为源语言,类型为 Language;第二个值为目标语言集合,类型为 List<Language>
	 * @throws NavException
	 * @throws XPathParseException
	 * @throws XPathEvalException
	 *             ;
	 */
private static Object[] getProjectLang(IFile iFile) throws NavException, XPathParseException, XPathEvalException {
    String projectFilePath = iFile.getProject().getLocation().toOSString() + System.getProperty("file.separator") + ".config";
    if (mapProjectLang.containsKey(projectFilePath)) {
        return mapProjectLang.get(projectFilePath);
    }
    VTDGen vg = new VTDGen();
    if (vg.parseFile(projectFilePath, true)) {
        VTDNav vn = vg.getNav();
        VTDUtils vu = new VTDUtils(vn);
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath("/projectDescription/hs/language/source");
        Object[] arrObj = new Object[2];
        if (ap.evalXPath() != -1) {
            String code = vu.getCurrentElementAttribut("code", "");
            String name = vu.getElementContent();
            String image = vu.getCurrentElementAttribut("image", "");
            String isBidi = vu.getCurrentElementAttribut("isbidi", "No");
            arrObj[0] = new Language(code, name, image, isBidi.equals("NO") ? false : true);
        }
        ap.selectXPath("/projectDescription/hs/language/target");
        List<Language> targetLangs = new ArrayList<Language>();
        while (ap.evalXPath() != -1) {
            String code = vu.getCurrentElementAttribut("code", "");
            String name = vu.getElementContent();
            String image = vu.getCurrentElementAttribut("image", "");
            String isBidi = vu.getCurrentElementAttribut("isbidi", "false");
            targetLangs.add(new Language(code, name, image, isBidi.equals("false") ? false : true));
        }
        arrObj[1] = targetLangs;
        return arrObj;
    } else {
        return null;
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav)

Example 13 with Language

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

the class ConcordanceSearchHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    if (!isEnabled()) {
        return null;
    }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            // IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
            IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
            ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
            List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
            if (lstDatabase.size() == 0) {
                MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
                return null;
            }
            String selectText = xliffEditor.getSelectPureText();
            if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
                selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
            } else if (selectText == null) {
                selectText = "";
            }
            String srcLang = xliffEditor.getSrcColumnName();
            String tgtLang = xliffEditor.getTgtColumnName();
            ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
            Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
            Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
            dialog.open();
            if (srcLangL.isBidi() || tgtLangL.isBidi()) {
                dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
            }
            if (selectText != null && !selectText.trim().equals("")) {
                dialog.initGroupIdAndSearch();
                IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
                ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
                Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
                IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
                IEvaluationContext currentState = evalService.getCurrentState();
                ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
                try {
                    command.executeWithChecks(executionEvent);
                } catch (Exception e1) {
                }
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ConcordanceSearchDialog(net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 14 with Language

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

the class LanguageCodesPreferencePage method removeLanguage.

// 删除当前选择的语言
protected void removeLanguage(List<?> languages) {
    try {
        String bundlePath = FileLocator.toFileURL(Activator.getDefault().getBundle().getEntry("")).getPath();
        for (Object object : languages) {
            if (object instanceof Language) {
                Language lang = (Language) object;
                languageModel.removeLanguage(lang);
                LocaleService.getLanguageConfiger().deleteLanguageByCode(lang.getCode());
                String imgPath = lang.getImagePath();
                if (!imgPath.equals("")) {
                    File file = new File(bundlePath + imgPath);
                    if (file.exists()) {
                        file.delete();
                    }
                }
            }
        }
    } catch (IOException e) {
        logger.error(Messages.getString("languagecode.LanguageCodesPreferencePage.logger4"), e);
        e.printStackTrace();
    }
    // refresh the viewer
    Tree tree = fFilteredTree.getViewer().getTree();
    try {
        tree.setRedraw(false);
        fFilteredTree.getViewer().refresh();
    } finally {
        tree.setRedraw(true);
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IOException(java.io.IOException) File(java.io.File)

Example 15 with Language

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

the class LanguageCodesPreferencePage method addLanguage.

// 添加新的语言
protected void addLanguage() {
    AddOrUpdateLanguageDialog dialog = new AddOrUpdateLanguageDialog(fFilteredTree.getShell(), AddOrUpdateLanguageDialog.DIALOG_ADD);
    dialog.setLanguageModel(languageModel);
    if (dialog.open() == IDialogConstants.OK_ID) {
        String strCode = dialog.getStrCode();
        String imagePath = dialog.getImagePath();
        String resultImagePath = "";
        if (!imagePath.equals("")) {
            File imgFile = new File(imagePath);
            if (imgFile.exists()) {
                try {
                    String bundlePath = FileLocator.toFileURL(Activator.getDefault().getBundle().getEntry("")).getPath();
                    String rsImagePath = bundlePath + "images/lang/" + strCode + ".png";
                    File rsImgFile = new File(rsImagePath);
                    if (!rsImgFile.exists()) {
                        rsImgFile.createNewFile();
                    }
                    ResourceUtils.copyFile(imgFile, rsImgFile);
                } catch (IOException e) {
                    logger.error(Messages.getString("languagecode.LanguageCodesPreferencePage.logger2"), e);
                    e.printStackTrace();
                }
            }
            resultImagePath = "images/lang/" + strCode + ".png";
        }
        Language language = new Language(strCode, dialog.getStrName(), resultImagePath, dialog.isBlnIsBidi());
        LocaleService.getLanguageConfiger().addLanguage(language);
        languageModel.getLanguages().add(language);
        languageModel.getLanguagesMap().put(strCode, language);
    }
    Tree tree = fFilteredTree.getViewer().getTree();
    try {
        tree.setRedraw(false);
        fFilteredTree.getViewer().refresh();
    } finally {
        tree.setRedraw(true);
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IOException(java.io.IOException) File(java.io.File)

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