use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class ShieldActivator method getFile.
/**
* 根据相对于插件根目录的相对路径,在插件中查找相应的文件,查找成功则返回对应的文件对象
* @param relativePath
* 对于插件根目录的相对路径
* @return 查找成功则返回对应的文件对象,否则返回 NULL;
*/
public static File getFile(String relativePath) {
File file = null;
URL langCodesURL = plugin.getBundle().getEntry(relativePath);
if (langCodesURL != null) {
try {
file = new File(FileLocator.toFileURL(langCodesURL).getPath());
} catch (Exception e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("shield.ShieldActivator.logger1");
Object[] args = { relativePath };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
}
}
return file;
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class TextUtil method loadISOLang.
private static void loadISOLang(String strLangFile) {
if (strLangFile == null) {
return;
}
ISOLang = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
// vg.setDoc(strLangFile.getBytes());
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strLangFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
int codeIndex;
String code = null;
String langName;
while ((ap.evalXPath()) != -1) {
codeIndex = vn.getAttrVal("code");
if (codeIndex != -1) {
code = vn.toString(codeIndex);
}
langName = vu.getElementPureText();
if (code != null && langName != null) {
ISOLang.put(code, langName);
}
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class TextUtil method loadLanguages.
private static void loadLanguages() {
descriptions = null;
isBidi = null;
descriptions = new Hashtable<String, String>();
isBidi = new Hashtable<String, String>();
String strFile = CoreActivator.LANGUAGE_CODE_PATH;
VTDGen vg = new VTDGen();
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
int codeIndex;
String code = null;
int bidiIndex;
String bidi = null;
String langName;
while ((ap.evalXPath()) != -1) {
codeIndex = vn.getAttrVal("code");
if (codeIndex != -1) {
code = vn.toString(codeIndex);
}
bidiIndex = vn.getAttrVal("bidi");
if (bidiIndex != -1) {
bidi = vn.toString(bidiIndex);
}
langName = vu.getElementPureText();
if (code != null && langName != null) {
descriptions.put(code, langName);
}
if (code != null && bidi != null) {
isBidi.put(code, bidi);
}
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class TextUtil method loadCountries.
private static void loadCountries() {
String strFile = CoreActivator.ISO3166_1_PAHT;
countries = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/ISO_3166-1_List_en/ISO_3166-1_Entry");
while ((ap.evalXPath()) != -1) {
countries.put(vu.getChildContent("ISO_3166-1_Alpha-2_Code_element"), vu.getChildContent("ISO_3166-1_Country_name"));
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of java.text.MessageFormat in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method updateStatusLine.
/**
* 在状态栏上显示被编辑文件的信息。
*/
public void updateStatusLine() {
if (table == null || table.isDisposed()) {
return;
}
SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
ViewportLayer viewportLayer = bodyLayer.getViewportLayer();
PositionCoordinate cellPosition = selectionLayer.getLastSelectedCellPosition();
if (cellPosition == null) {
return;
}
// int order = LayerUtil.convertRowPosition(selectionLayer, cellPosition.rowPosition, viewportLayer);
// Bug #2317:选中文本段后排序,不会刷新状态栏中的序号
int[] selectedRowPostions = selectionLayer.getFullySelectedRowPositions();
if (selectedRowPostions.length <= 0) {
return;
}
// 刷新选中行的术语,使其排序后保持高亮显示
// if (!isHorizontalLayout()) {
// int rowPosition = selectedRowPostions[0];
// rowPosition *= VerticalNatTableConfig.ROW_SPAN;
// cellPosition.set(rowPosition, cellPosition.getColumnPosition());
// } else {
// cellPosition.set(selectedRowPostions[0], cellPosition.getColumnPosition());
// }
// if (!FindReplaceDialog.isOpen) {
// CellRegion cellRegion = new CellRegion(cellPosition, new Region(0, selectionLayer.getWidth()));
// ActiveCellRegion.setActiveCellRegion(cellRegion);
// }
int order = LayerUtil.convertRowPosition(selectionLayer, selectedRowPostions[0], viewportLayer);
order += viewportLayer.getOriginRowPosition() + 1;
// 垂直布局时order需要进行两行递增的处理
if (!isHorizontalLayout) {
order = (int) Math.ceil(order / 2.0);
}
MessageFormat messageFormat = null;
if (order > 0) {
/* 一个Xliff文件,可能有多个File节点,这里使用File结点的original属性 */
/* 当前文件:{0} | 顺序号:{1} | 可见文本段数:{2} | 文本段总数:{3} | 当前用户名" */
messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat1"));
} else {
messageFormat = new MessageFormat(Messages.getString("editor.XLIFFEditorImplWithNatTable.messageFormat2"));
}
String fileName = "";
// 添加 Project Name
IEditorInput editorInput = getEditorInput();
String filePath = "";
if (isMultiFile()) {
if (getSelectedRowIds().size() > 0) {
filePath = RowIdUtil.getFileNameByRowId(getSelectedRowIds().get(0));
fileName = ResourceUtils.toWorkspacePath(filePath);
}
} else {
fileName = getEditorInput().getName();
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
filePath = fileEditorInput.getFile().getLocation().toOSString();
fileName = fileEditorInput.getFile().getFullPath().toOSString();
}
}
String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
int editableTuSum = handler.countEditableTransUnit();
int tuSum = handler.countTransUnit();
// int translatedSum1 = handler
// .getNodeCount(filePath,
// "/xliff/file/body/trans-unit[@approved = 'yes' and target/@state != 'translated' and target/@state != 'signed-off']");
// int translatedSum2 = handler.getNodeCount(filePath,
// "/xliff/file/body/trans-unit/target[@state = 'translated' or @state = 'signed-off']");
// int approveSum1 = handler.getNodeCount(filePath,
// "/xliff/file/body/trans-unit[not(@approved='yes') and target/@state='signed-off']");
// int approveSum2 = handler.getNodeCount(filePath, "/xliff/file/body/trans-unit[@approved = 'yes']");
int translatedSum = handler.getTranslatedCount();
int approveedSum = handler.getApprovedCount();
int approveP = (int) Math.floor(approveedSum / (double) tuSum * 100.00);
int translatedP = (int) Math.floor(translatedSum / (double) tuSum * 100.00);
translationItem.setProgressValue(translatedP);
approveItem.setProgressValue(approveP);
// 将信息显示在状态栏
String message = messageFormat.format(new String[] { fileName, String.valueOf(order), String.valueOf(editableTuSum), String.valueOf(tuSum), systemUser });
statusLineManager.setMessage(statusLineImage, message);
}
Aggregations