Skip to content

Commit

Permalink
Added support for WPML XLIFF files
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Dec 1, 2019
1 parent e7a9e78 commit 2fc3280
Show file tree
Hide file tree
Showing 12 changed files with 575 additions and 30 deletions.
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 = "1.5.2";
public static final String BUILD = "20191024_1131";
public static final String VERSION = "1.6.0";
public static final String BUILD = "20191201_1444";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
14 changes: 9 additions & 5 deletions src/com/maxprograms/converters/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.maxprograms.converters.sdlxliff.Sdl2Xliff;
import com.maxprograms.converters.ts.Ts2Xliff;
import com.maxprograms.converters.txml.Txml2Xliff;
import com.maxprograms.converters.wpml.Wpml2Xliff;
import com.maxprograms.converters.xml.Xml2Xliff;
import com.maxprograms.xliff2.ToXliff2;
import com.maxprograms.xml.Catalog;
Expand Down Expand Up @@ -290,6 +291,7 @@ private static void help() {
+ " TEXT = Plain Text\n"
+ " TS = TS (Qt Linguist translation source)\n"
+ " TXML = TXML Document\n"
+ " WPML = WPML XLIFF\n"
+ " XML = XML Document\n"
+ " XMLG = XML (Generic)\n";
System.out.println(help);
Expand All @@ -311,11 +313,11 @@ public static Vector<String> addSkeleton(String fileName, String catalog) {
Element skl = header.getChild("skl");
Element external = skl.getChild("external-file");
String sklName = external.getAttributeValue("href");
sklName = sklName.replaceAll("&amp;", "&");
sklName = sklName.replaceAll("&lt;", "<");
sklName = sklName.replaceAll("&gt;", ">");
sklName = sklName.replaceAll("&apos;", "\'");
sklName = sklName.replaceAll("&quot;", "\"");
sklName = sklName.replace("&amp;", "&");
sklName = sklName.replace("&lt;", "<");
sklName = sklName.replace("&gt;", ">");
sklName = sklName.replace("&apos;", "\'");
sklName = sklName.replace("&quot;", "\"");
if (!deleted.contains(sklName)) {
File skeleton = new File(sklName);
Element internal = new Element("internal-file");
Expand Down Expand Up @@ -378,6 +380,8 @@ public static Vector<String> run(Hashtable<String, String> params) {
result = Ts2Xliff.run(params);
} else if (format.equals(FileFormats.TXML)) {
result = Txml2Xliff.run(params);
} else if (format.equals(FileFormats.WPML)) {
result = Wpml2Xliff.run(params);
} else if (format.equals(FileFormats.XML)) {
result = Xml2Xliff.run(params);
} else if (format.equals(FileFormats.XMLG)) {
Expand Down
5 changes: 3 additions & 2 deletions src/com/maxprograms/converters/EncodingResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static Charset getEncoding(String fileName, String fileType) {
} else if (fileType.equals(FileFormats.XML) || fileType.equals(FileFormats.XMLG)
|| fileType.equals(FileFormats.TXML) || fileType.equals(FileFormats.RESX)
|| fileType.equals(FileFormats.INX) || fileType.equals(FileFormats.TS)
|| fileType.equals(FileFormats.DITA) || fileType.equals(FileFormats.SDLXLIFF)) {
|| fileType.equals(FileFormats.DITA) || fileType.equals(FileFormats.SDLXLIFF)
|| fileType.equals(FileFormats.WPML)) {
try {
return getXMLEncoding(fileName);
} catch (IOException e) {
Expand Down Expand Up @@ -141,7 +142,7 @@ private static Charset getXMLEncoding(String fileName) throws IOException {
String line = buffer.readLine();
if (line.startsWith("<?")) {
line = line.substring(2, line.indexOf("?>"));
line = line.replaceAll("\'", "\"");
line = line.replace("\'", "\"");
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
Expand Down
12 changes: 11 additions & 1 deletion src/com/maxprograms/converters/FileFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ private FileFormats() {
public static final String SDLXLIFF = "SDLXLIFF Document";
public static final String TS = "TS (Qt Linguist translation source)";
public static final String TXML = "TXML Document";
public static final String WPML = "WPML XLIFF";
public static final String XML = "XML Document";
public static final String XMLG = "XML (Generic)";

protected static final String[] formats = { INX, IDML, DITA, HTML, JS, JAVA, MIF, OFF, OO, TEXT, PO, RC, RESX,
SDLXLIFF, TS, TXML, XML, XMLG };
SDLXLIFF, TS, TXML, WPML, XML, XMLG };

public static String detectFormat(String fileName) {

Expand Down Expand Up @@ -88,6 +89,9 @@ public static String detectFormat(String fileName) {
if (string.indexOf("<xliff") != -1 && string.indexOf("xmlns:sdl") != -1) {
return SDLXLIFF;
}
if (string.indexOf("<xliff") != -1 && string.indexOf("<![CDATA[") != -1) {
return WPML;
}
if (string.indexOf("<txml ") != -1) {
return TXML;
}
Expand Down Expand Up @@ -250,6 +254,9 @@ public static String getShortName(String type) {
if (type.equals(TXML)) {
return "TXML";
}
if (type.equals(WPML)) {
return "WPML";
}
if (type.equals(XML)) {
return "XML";
}
Expand Down Expand Up @@ -308,6 +315,9 @@ public static String getFullName(String type) {
if (type.equals("TXML")) {
return TXML;
}
if (type.equals("WPML")) {
return WPML;
}
if (type.equals("XML")) {
return XML;
}
Expand Down
13 changes: 8 additions & 5 deletions src/com/maxprograms/converters/Merge.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.maxprograms.converters.sdlxliff.Xliff2Sdl;
import com.maxprograms.converters.ts.Xliff2Ts;
import com.maxprograms.converters.txml.Xliff2Txml;
import com.maxprograms.converters.wpml.Xliff2Wpml;
import com.maxprograms.converters.xml.Xliff2Xml;
import com.maxprograms.xliff2.FromXliff2;
import com.maxprograms.xml.Catalog;
Expand Down Expand Up @@ -375,6 +376,8 @@ private static Vector<String> run(Hashtable<String, String> params) {
result = Xliff2Ts.run(params);
} else if (dataType.equals(FileFormats.TXML) || dataType.equals("x-txml")) {
result = Xliff2Txml.run(params);
} else if (dataType.equals(FileFormats.WPML) || dataType.equals("x-wpmlxliff")) {
result = Xliff2Wpml.run(params);
} else if (dataType.equals(FileFormats.XML) || dataType.equals("xml")) {
result = Xliff2Xml.run(params);
} else {
Expand Down Expand Up @@ -405,11 +408,11 @@ private static String getSkeleton() throws IOException {
Element external = mskl.getChild("external-file");
if (external != null) {
result = external.getAttributeValue("href");
result = result.replaceAll("&amp;", "&");
result = result.replaceAll("&lt;", "<");
result = result.replaceAll("&gt;", ">");
result = result.replaceAll("&apos;", "\'");
result = result.replaceAll("&quot;", "\"");
result = result.replace("&amp;", "&");
result = result.replace("&lt;", "<");
result = result.replace("&gt;", ">");
result = result.replace("&apos;", "\'");
result = result.replace("&quot;", "\"");
} else {
Element internal = mskl.getChild("internal-file");
if (internal != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/com/maxprograms/converters/TmxExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ public static String extractText(Element src) {
}

private static String restoreChars(String string) {
String result = string.replaceAll(MATHLT, "<");
result = result.replaceAll(MATHGT, ">");
result = result.replaceAll(DOUBLEPRIME, "\"");
return result.replaceAll(GAMP, "&");
String result = string.replace(MATHLT, "<");
result = result.replace(MATHGT, ">");
result = result.replace(DOUBLEPRIME, "\"");
return result.replace(GAMP, "&");
}

private static void writeString(FileOutputStream output, String input) throws IOException {
Expand Down
6 changes: 3 additions & 3 deletions src/com/maxprograms/converters/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ private Utils() {
}

public static String cleanString(String string) {
String result = string.replaceAll("&", "&amp;");
result = result.replaceAll("<", "&lt;");
result = result.replaceAll(">", "&gt;");
String result = string.replace("&", "&amp;");
result = result.replace("<", "&lt;");
result = result.replace(">", "&gt;");
return XMLUtils.validChars(result);
}

Expand Down
Loading

0 comments on commit 2fc3280

Please sign in to comment.