Skip to content

Commit

Permalink
Added xmlfilter parameter to conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Dec 5, 2022
1 parent f4e4ae3 commit 2094a73
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Where:
-config: (optional) configuration file to use when converting JSON documents
-embed: (optional) store skeleton inside the XLIFF file
-paragraph: (optional) use paragraph segmentation
-xmlfilter: (optional) folder containing configuration files for the XML filter
-2.0: (optional) generate XLIFF 2.0
-charsets: (optional) display a list of available character sets and exit
Expand Down
Binary file modified lib/openxliff.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private Constants() {

public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "2.11.0";
public static final String BUILD = "20221202_1152";
public static final String VERSION = "2.12.0";
public static final String BUILD = "20221205_1411";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
16 changes: 15 additions & 1 deletion src/com/maxprograms/converters/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static void main(String[] args) {
String catalog = "";
String ditaval = "";
String config = "";
String xmlfilter = "";
boolean embed = false;
boolean paragraph = false;
boolean xliff20 = false;
Expand Down Expand Up @@ -143,6 +144,9 @@ public static void main(String[] args) {
if (arg.equals("-paragraph")) {
paragraph = true;
}
if (arg.equals("-xmlfilter") && (i + 1) < arguments.length) {
xmlfilter = arguments[i + 1];
}
if (arg.equals("-2.0")) {
xliff20 = true;
}
Expand Down Expand Up @@ -218,6 +222,14 @@ public static void main(String[] args) {
logger.log(Level.ERROR, "SRX file does not exist.");
return;
}
if (xmlfilter.isEmpty()) {
String home = System.getenv("OpenXLIFF_HOME");
if (home == null) {
home = System.getProperty("user.dir");
}
File filtersFolder = new File(new File(home), "xmlfilter");
xmlfilter = filtersFolder.getAbsolutePath();
}
if (catalog.isEmpty()) {
String home = System.getenv("OpenXLIFF_HOME");
if (home == null) {
Expand Down Expand Up @@ -255,6 +267,7 @@ public static void main(String[] args) {
params.put("paragraph", paragraph ? "yes" : "no");
params.put("srxFile", srx);
params.put("srcLang", srcLang);
params.put("xmlfilter", xmlfilter);
if (!tgtLang.isEmpty()) {
params.put("tgtLang", tgtLang);
}
Expand Down Expand Up @@ -291,7 +304,7 @@ private static void help() {
+ "[-skl skeletonFile] [-xliff xliffFile] "
+ "[-type fileType] [-enc encoding] [-srx srxFile] "
+ "[-catalog catalogFile] [-divatal ditaval] [-config configFile] "
+ "[-embed] [-paragraph] [-2.0] [-charsets]\n\n"
+ "[-embed] [-paragraph] [-xmlfilter folder][-2.0] [-charsets]\n\n"
+ "Where:\n\n"
+ " -help: (optional) Display this help information and exit\n"
+ " -version: (optional) Display version & build information and exit\n"
Expand All @@ -308,6 +321,7 @@ private static void help() {
+ " -config: (optional) configuration file to use when converting JSON documents\n"
+ " -embed: (optional) store skeleton inside the XLIFF file\n"
+ " -paragraph: (optional) use paragraph segmentation\n"
+ " -xmlfilter: (optional) folder containing configuration files for the XML filter\n"
+ " -2.0: (optional) generate XLIFF 2.0\n"
+ " -charsets: (optional) display a list of available character sets and exit\n\n"
+ "Document Types\n\n"
Expand Down
1 change: 1 addition & 0 deletions src/com/maxprograms/converters/ditamap/DitaMap2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public static List<String> run(Map<String, String> params) {
params2.put("srxFile", params.get("srxFile"));
params2.put("paragraph", params.get("paragraph"));
params2.put("dita_based", "yes");
params2.put("xmlfilter", params.get("xmlfilter"));
String tComments = params.get("translateComments");
if (tComments != null) {
params2.put("translateComments", tComments);
Expand Down
27 changes: 14 additions & 13 deletions src/com/maxprograms/converters/office/Office2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,29 @@ public static List<String> run(Map<String, String> params) {
cleanTags(tmp.getAbsolutePath(), catalog);
}
try {
Map<String, String> table = new HashMap<>();
table.put("source", tmp.getAbsolutePath());
table.put("xliff", tmp.getAbsolutePath() + ".xlf");
table.put("skeleton", tmp.getAbsolutePath() + ".skl");
table.put("catalog", params.get("catalog"));
table.put("srcLang", params.get("srcLang"));
Map<String, String> params2 = new HashMap<>();
params2.put("source", tmp.getAbsolutePath());
params2.put("xliff", tmp.getAbsolutePath() + ".xlf");
params2.put("skeleton", tmp.getAbsolutePath() + ".skl");
params2.put("catalog", params.get("catalog"));
params2.put("srcLang", params.get("srcLang"));
String tgtLang = params.get("tgtLang");
if (tgtLang != null) {
table.put("tgtLang", tgtLang);
params2.put("tgtLang", tgtLang);
}
table.put("srcEncoding", params.get("srcEncoding"));
table.put("paragraph", params.get("paragraph"));
table.put("srxFile", params.get("srxFile"));
table.put("format", params.get("format"));
params2.put("srcEncoding", params.get("srcEncoding"));
params2.put("paragraph", params.get("paragraph"));
params2.put("srxFile", params.get("srxFile"));
params2.put("format", params.get("format"));
params2.put("xmlfilter", params.get("xmlfilter"));
List<String> res = null;
if (params.get("format").equals(FileFormats.OFF)) {
res = MSOffice2Xliff.run(table);
res = MSOffice2Xliff.run(params2);
if (tmp.getName().indexOf("slide") != -1) {
isPPTX = true;
}
} else {
res = Xml2Xliff.run(table);
res = Xml2Xliff.run(params2);
}
if (Constants.SUCCESS.equals(res.get(0))) {
if (countSegments(tmp.getAbsolutePath() + ".xlf") > 0) {
Expand Down
11 changes: 4 additions & 7 deletions src/com/maxprograms/converters/xml/Xml2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public static List<String> run(Map<String, String> params) {
targetLanguage = params.get("tgtLang");
srcEncoding = params.get("srcEncoding");
String catalogFile = params.get("catalog");
String xmlfilter = params.get("xmlfilter");
String elementSegmentation = params.get("paragraph");
String initSegmenter = params.get("srxFile");
String isInDesign = params.get("InDesign");
Expand Down Expand Up @@ -146,7 +147,7 @@ public static List<String> run(Map<String, String> params) {
currentCatalog = catalogFile;
}
boolean autoConfiguration = false;
String iniFile = getIniFile(inputFile);
String iniFile = getIniFile(xmlfilter, inputFile);
if (generic) {
File temp = File.createTempFile("config_", ".xml");
iniFile = temp.getAbsolutePath();
Expand Down Expand Up @@ -248,12 +249,8 @@ public static List<String> run(Map<String, String> params) {
return result;
}

private static String getIniFile(String fileName) throws SAXException, IOException, ParserConfigurationException {
String home = System.getenv("OpenXLIFF_HOME");
if (home == null) {
home = System.getProperty("user.dir");
}
File folder = new File(home, "xmlfilter");
private static String getIniFile(String filtersFolder, String fileName) throws SAXException, IOException, ParserConfigurationException {
File folder = new File(filtersFolder);
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(catalog);
builder.setValidating(false);
Expand Down

0 comments on commit 2094a73

Please sign in to comment.