Skip to content

Commit 1a75b29

Browse files
committed
Added merge of XLIFF 2.0
1 parent e0a46a4 commit 1a75b29

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/com/maxprograms/javapm/MergeXliff.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.lang.System.Logger;
1616
import java.lang.System.Logger.Level;
17+
import java.nio.file.Files;
1718
import java.text.MessageFormat;
1819
import java.util.List;
1920

@@ -73,7 +74,7 @@ private static void mergeXliff(String src, String xliff)
7374
throws IOException, SAXException, ParserConfigurationException {
7475
File srcFolder = new File(src);
7576
if (!srcFolder.exists()) {
76-
throw new IOException("'src' folder does not exist");
77+
Files.createDirectories(srcFolder.toPath());
7778
}
7879
File catalogFolder = new File("catalog");
7980
if (!catalogFolder.exists()) {
@@ -93,24 +94,26 @@ private static void mergeXliff(String src, String xliff)
9394
if (!"xliff".equals(root.getName())) {
9495
throw new IOException("Selected file is not an XLIFF document");
9596
}
97+
String tgtLang = "";
9698
if (root.getAttributeValue("version").startsWith("2.")) {
97-
xliffFile = process20(xliffFile, doc);
99+
tgtLang = root.getAttributeValue("trgLang");
98100
} else {
99-
xliffFile = process12(xliffFile, doc);
101+
Element file = root.getChild("file");
102+
tgtLang = file.getAttributeValue("target-language");
100103
}
104+
if (tgtLang.isEmpty()) {
105+
throw new IOException("Target language not set");
106+
}
107+
xliffFile = processFiles(xliffFile, doc, tgtLang);
101108
List<String> result = Merge.merge(xliffFile.getAbsolutePath(), src, catalog.getAbsolutePath(), true);
102109
if (Constants.ERROR.equals(result.get(0))) {
103110
throw new IOException(result.get(1));
104111
}
105112
}
106113

107-
private static File process12(File xliffFile, Document doc) throws IOException {
114+
private static File processFiles(File xliffFile, Document doc, String tgtLang) throws IOException {
108115
Element root = doc.getRootElement();
109116
List<Element> files = root.getChildren("file");
110-
String tgtLang = files.get(0).getAttributeValue("target-language");
111-
if (tgtLang.isEmpty()) {
112-
throw new IOException("Target language not set");
113-
}
114117
for (int i = 0; i < files.size(); i++) {
115118
Element file = files.get(i);
116119
String original = file.getAttributeValue("original");
@@ -135,13 +138,10 @@ private static String updateOriginal(String original, String tgtLang) throws IOE
135138
return name + "_" + tgtLang + ".properties";
136139
}
137140

138-
private static File process20(File xliffFile, Document doc) {
139-
return null;
140-
}
141-
142141
private static void help() {
143142
String launcher = System.getProperty("file.separator").equals("/") ? "mergexliff.sh" : "mergexliff.bat";
144-
MessageFormat mf = new MessageFormat("Usage:\n\n {0} [-help] -src sourceFolder -xliff xliffFile\n\nWhere:\n\n -help: (optional) display this help information and exit\n -src: source code folder\n -xliff: XLIFF file to merge\n\n");
143+
MessageFormat mf = new MessageFormat(
144+
"Usage:\n\n {0} [-help] -src sourceFolder -xliff xliffFile\n\nWhere:\n\n -help: (optional) display this help information and exit\n -src: source code folder\n -xliff: XLIFF file to merge\n\n");
145145
System.out.println(mf.format(new String[] { launcher }));
146146
}
147147
}

0 commit comments

Comments
 (0)