use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.
the class LanguageConfiger method getAllLanguage.
/**
* 返回所有语言列表,key:code,value:<code>Language</code>
*/
public Map<String, Language> getAllLanguage() {
Map<String, Language> result = new HashMap<String, Language>();
AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
String codeAttr = "code";
String bidiAttr = "bidi";
String imgAttr = "image";
String bidiYes = "Yes";
try {
tempAp.selectXPath("/languages/lang");
while (tempAp.evalXPath() != -1) {
Map<String, String> attrs = vu.getCurrentElementAttributs();
String code = attrs.get(codeAttr);
String bidi = attrs.get(bidiAttr);
String img = attrs.get(imgAttr);
String langName = vu.getElementPureText();
boolean isBidi = false;
if (code != null && langName != null) {
if (bidi != null && bidi.equals(bidiYes)) {
isBidi = true;
}
result.put(code, new Language(code, langName, img == null ? "" : img, isBidi));
}
}
} catch (XPathParseException e) {
LOGGER.error("", e);
} catch (XPathEvalException e) {
LOGGER.error("", e);
} catch (NavException e) {
LOGGER.error("", e);
}
return result;
}
use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.
the class LanguageConfiger method getLanguageByCode.
/**
* 返回Code对应的Language对象,如果在配置中找到则返回null
* @param code
* @return ;
*/
public Language getLanguageByCode(String code) {
AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
String bidiAttr = "bidi";
String imgAttr = "image";
String bidiYes = "Yes";
try {
tempAp.selectXPath("/languages/lang[@code='" + code + "']");
if (tempAp.evalXPath() != -1) {
Map<String, String> attrs = vu.getCurrentElementAttributs();
String bidi = attrs.get(bidiAttr);
String img = attrs.get(imgAttr);
String langName = vu.getElementPureText();
boolean isBidi = false;
if (code != null && langName != null) {
if (bidi != null && bidi.equals(bidiYes)) {
isBidi = true;
}
return new Language(code, langName, img == null ? "" : img, isBidi);
}
}
} catch (XPathParseException e) {
LOGGER.error("", e);
} catch (XPathEvalException e) {
LOGGER.error("", e);
} catch (NavException e) {
LOGGER.error("", e);
}
return null;
}
use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.
the class TermBaseSearchHandler 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;
IProject project = ((FileEditorInput) editor.getEditorInput()).getFile().getProject();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(false);
if (lstDatabase == null || lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.TermBaseSearchHandler.msgTitle"), Messages.getString("handler.TermBaseSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
selectText = resetCeanString(selectText);
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
TermBaseSearchDialog dialog = new TermBaseSearchDialog(editor.getSite().getShell(), project, 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.search();
}
}
return null;
}
use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.
the class ProjectSettingTBPage method checkDbHashMatch.
/**
* 需要调用Database模块 检查当前项目在库中是否有语言对的匹配
* @param dbModel
* 数据库信息;
*/
public void checkDbHashMatch(DatabaseModelBean dbModel) {
Language srcLang = super.projectInfoBean.getSourceLang();
DBOperator dbOp = DatabaseService.getDBOperator(dbModel.toDbMetaData());
try {
if (dbOp != null) {
dbOp.start();
dbModel.setHasMatch(dbOp.checkHasMatchs(srcLang.getCode(), "B"));
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
dbModel.setHasMatch(false);
} finally {
if (dbOp != null) {
try {
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
}
use of net.heartsome.cat.common.locale.Language in project translationstudio8 by heartsome.
the class Txt2TbxConverter method doConvert.
/**
* (non-Javadoc)
* @see net.heartsome.cat.document.converter.AbstractConverter#doConvert(java.lang.String,
* org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public void doConvert(String targetFile, IProgressMonitor monitor) throws Exception {
try {
monitor.beginTask("", 10);
monitor.worked(2);
out = new FileOutputStream(new File(targetFile));
File f = new File(txtFile);
String encoding = FileEncodingDetector.detectFileEncoding(f);
TxtRowReader reader = new TxtRowReader(f, encoding);
int rowsNum = reader.getLineNumber();
if (rowsNum < 2) {
throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
}
// read header
List<String[]> h = reader.read(1);
if (h == null || h.size() == 0) {
throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
}
String[] hv = h.get(0);
if (hv == null || hv.length < 2) {
throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
}
Map<String, Language> defaultLanguage = LocaleService.getDefaultLanguage();
List<String> _temp = new ArrayList<String>();
for (String s : hv) {
s = LanguageUtils.convertLangCode(s);
if (_temp.contains(s)) {
throw new Exception(Messages.getString("converter.common.vaild.duplicatelangcode.error"));
}
if (defaultLanguage.get(s) == null) {
throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
}
_temp.add(s);
}
if (_temp.size() < 2) {
throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
}
header = _temp.toArray(new String[] {});
// generate header
String s = generateTbxHeader(header[0]);
writeString(s);
// generate body
int readSize = 10;
List<String[]> rs = null;
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 8);
subMonitor.beginTask("", rowsNum / readSize == 0 ? 1 : rowsNum / readSize);
while ((rs = reader.read(readSize)) != null) {
for (String[] r : rs) {
if (r == null || r.length < 2) {
continue;
}
int loopSize = r.length < header.length ? r.length : header.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < loopSize; i++) {
String value = r[i];
String lang = header[i];
sb.append("<langSet id=\"_" + (System.currentTimeMillis() + 1) + "\" xml:lang=\"" + lang + "\">\n");
sb.append("<tig>\n");
sb.append("<term>" + value + "</term>\n");
sb.append("</tig>\n");
sb.append("</langSet>\n");
}
if (sb.length() != 0) {
writeString("<termEntry id=\"_" + System.currentTimeMillis() + "\">\n");
writeString(sb.toString());
writeString("</termEntry>\n");
}
subMonitor.worked(1);
}
if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
}
// generate end
s = generateTbxEnd();
if (s != null && s.length() != 0) {
writeString(s);
}
subMonitor.done();
} finally {
out.close();
monitor.done();
}
}
Aggregations