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));
}
}
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;
}
}
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;
}
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);
}
}
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);
}
}
Aggregations