use of java.lang.System.Logger in project OpenXLIFF by rmraya.
the class Jscript2xliff method run.
public static List<String> run(Map<String, String> params) {
List<String> result = new ArrayList<>();
String inputFile = params.get("source");
String xliffFile = params.get("xliff");
String skeletonFile = params.get("skeleton");
sourceLanguage = params.get("srcLang");
String targetLanguage = params.get("tgtLang");
String encoding = params.get("srcEncoding");
String tgtLang = "";
if (targetLanguage != null) {
tgtLang = "\" target-language=\"" + targetLanguage;
}
try {
try (FileInputStream stream = new FileInputStream(inputFile)) {
try (InputStreamReader input = new InputStreamReader(stream, encoding)) {
BufferedReader buffer = new BufferedReader(input);
output = new FileOutputStream(xliffFile);
writeString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
writeString("<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd\">\n");
writeString("<file original=\"" + inputFile + "\" source-language=\"" + sourceLanguage + tgtLang + "\" tool-id=\"" + Constants.TOOLID + "\" datatype=\"javascript\">\n");
writeString("<header>\n");
writeString(" <skl>\n");
writeString(" <external-file href=\"" + Utils.cleanString(skeletonFile) + "\"/>\n");
writeString(" </skl>\n");
writeString(" <tool tool-version=\"" + Constants.VERSION + " " + Constants.BUILD + "\" tool-id=\"" + Constants.TOOLID + "\" tool-name=\"" + Constants.TOOLNAME + "\"/>\n");
writeString("</header>\n");
writeString("<?encoding " + encoding + "?>\n");
writeString("<body>\n");
skeleton = new FileOutputStream(skeletonFile);
String line;
String comment = "";
while ((line = buffer.readLine()) != null) {
line = line + "\n";
comment = findComment(line);
if (!comment.isEmpty()) {
line = line.substring(0, line.indexOf(comment));
}
if (line.indexOf('\"') == -1 && line.indexOf('\'') == -1) {
// no text in this line
writeSkeleton(line + comment);
} else {
// check for strings to extract
int number = countQuotes(line, '\"') + countQuotes(line, '\'');
if (number > 0 && number % 2 == 0) {
// all strings closed in the same line
extractStrings(line);
writeSkeleton(comment);
} else {
// check if the line ends with "/"
if (line.trim().endsWith("/") && !line.trim().endsWith("//")) {
String nextLine = buffer.readLine();
if (nextLine == null) {
result.add(Constants.ERROR);
result.add("Unexpected end of file.");
return result;
}
comment = findComment(nextLine);
if (!comment.isEmpty()) {
nextLine = nextLine.substring(0, nextLine.indexOf(comment));
}
line = line + nextLine;
continue;
}
result.add(Constants.ERROR);
result.add("Found a string that is not properly closed.");
return result;
}
}
}
skeleton.close();
writeString("</body>\n");
writeString("</file>\n");
writeString("</xliff>");
}
}
output.close();
result.add(Constants.SUCCESS);
} catch (IOException e) {
Logger logger = System.getLogger(Jscript2xliff.class.getName());
logger.log(Level.ERROR, "Error converting JavaScript file.", e);
result.add(Constants.ERROR);
result.add(e.getMessage());
}
return result;
}
use of java.lang.System.Logger in project OpenXLIFF by rmraya.
the class Xliff2Wpml method run.
public static List<String> run(Map<String, String> params) {
List<String> result = new ArrayList<>();
String xliffFile = params.get("xliff");
String sklFile = params.get("skeleton");
String outputFile = params.get("backfile");
try {
catalog = new Catalog(params.get("catalog"));
loadXliff(xliffFile);
loadSkeleton(sklFile);
recurseSkeleton(skeleton.getRootElement());
File f = new File(outputFile);
File p = f.getParentFile();
if (p == null) {
p = new File(System.getProperty("user.dir"));
}
if (!p.exists()) {
p.mkdirs();
}
if (!f.exists()) {
Files.createFile(Paths.get(f.toURI()));
}
try (FileOutputStream out = new FileOutputStream(outputFile)) {
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
outputter.output(skeleton, out);
}
result.add(Constants.SUCCESS);
} catch (IOException | SAXException | ParserConfigurationException | URISyntaxException e) {
Logger logger = System.getLogger(Xliff2Wpml.class.getName());
logger.log(Level.ERROR, "Error merging WPML file.", e);
result.add(Constants.ERROR);
result.add(e.getMessage());
}
return result;
}
use of java.lang.System.Logger in project OpenXLIFF by rmraya.
the class Xliff2Ts method run.
public static List<String> run(Map<String, String> params) {
List<String> result = new ArrayList<>();
try {
xliffFile = params.get("xliff");
loadSegments();
String sklFile = params.get("skeleton");
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(sklFile);
recurseSkl(doc.getRootElement());
String outputFile = params.get("backfile");
File f = new File(outputFile);
File p = f.getParentFile();
if (p == null) {
p = new File(System.getProperty("user.dir"));
}
if (!p.exists()) {
p.mkdirs();
}
if (!f.exists()) {
Files.createFile(Paths.get(f.toURI()));
}
try (FileOutputStream output = new FileOutputStream(f)) {
XMLOutputter outputter = new XMLOutputter();
outputter.setEncoding(StandardCharsets.UTF_8);
outputter.preserveSpace(true);
outputter.escapeQuotes(true);
outputter.setEmptyDoctype(true);
outputter.output(doc, output);
}
result.add(Constants.SUCCESS);
} catch (IOException | SAXException | ParserConfigurationException e) {
Logger logger = System.getLogger(Xliff2Ts.class.getName());
logger.log(Level.ERROR, "Error merging TS file.", e);
result.add(Constants.ERROR);
result.add(e.getMessage());
}
return result;
}
use of java.lang.System.Logger in project OpenXLIFF by rmraya.
the class Xliff2Txml method run.
public static List<String> run(Map<String, String> params) {
List<String> result = new ArrayList<>();
String sklFile = params.get("skeleton");
xliffFile = params.get("xliff");
catalog = params.get("catalog");
String encoding = params.get("encoding");
String outputFile = params.get("backfile");
try {
loadSegments();
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(sklFile);
Element root = doc.getRootElement();
replaceTargets(root);
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
outputter.setEncoding(Charset.forName(encoding));
File f = new File(outputFile);
File p = f.getParentFile();
if (p == null) {
p = new File(System.getProperty("user.dir"));
}
if (!p.exists()) {
p.mkdirs();
}
if (!f.exists()) {
Files.createFile(Paths.get(f.toURI()));
}
try (FileOutputStream output = new FileOutputStream(f)) {
outputter.output(doc, output);
}
result.add(Constants.SUCCESS);
} catch (IOException | SAXException | ParserConfigurationException | URISyntaxException e) {
Logger logger = System.getLogger(Xliff2Txml.class.getName());
logger.log(Level.ERROR, "Error merging file", e);
result.add(Constants.ERROR);
if (e.getMessage() != null) {
result.add(e.getMessage());
} else {
result.add("Unknown error");
}
}
return result;
}
use of java.lang.System.Logger in project OpenXLIFF by rmraya.
the class Xliff2Rc method run.
public static List<String> run(Map<String, String> params) {
List<String> result = new ArrayList<>();
dlgText = new HashMap<>();
sklFile = params.get("skeleton");
xliffFile = params.get("xliff");
catalog = params.get("catalog");
encoding = params.get("encoding");
try {
File tempFile = File.createTempFile("tempRC", ".temp");
destTemp = tempFile.getAbsolutePath();
output = new FileOutputStream(destTemp);
loadSegments();
dlgInitExists(params);
try (InputStreamReader input = new InputStreamReader(new FileInputStream(sklFile), StandardCharsets.UTF_8)) {
BufferedReader buffer = new BufferedReader(input);
String line;
while ((line = buffer.readLine()) != null) {
line = line + "\n";
if (line.indexOf("%%%") != -1) {
//
// contains translatable text
//
int index = line.indexOf("%%%");
while (index != -1) {
String start = line.substring(0, index);
writeString(start);
line = line.substring(index + 3);
String code = line.substring(0, line.indexOf("%%%"));
line = line.substring(line.indexOf("%%%") + 3);
Element segment = segments.get(code);
if (segment != null) {
if (segment.getAttributeValue("approved", "no").equalsIgnoreCase("Yes")) {
Element target = segment.getChild("target");
if (target != null) {
writeString(converDlgInit(target.getText(), code));
} else {
throw new UnexistentSegmentException();
}
} else {
// process source
Element source = segment.getChild("source");
writeString(converDlgInit(source.getText(), code));
}
} else {
throw new UnexistentSegmentException();
}
index = line.indexOf("%%%");
if (index == -1) {
writeString(line);
}
}
// end while
} else {
writeString(line);
}
}
}
output.close();
dlgInitLengths(params);
Files.delete(Paths.get(tempFile.toURI()));
result.add(Constants.SUCCESS);
} catch (IOException | SAXException | ParserConfigurationException | UnexistentSegmentException | URISyntaxException e) {
Logger logger = System.getLogger(Xliff2Rc.class.getName());
logger.log(Level.ERROR, "Error merging RC file", e);
result.add(Constants.ERROR);
result.add(e.getMessage());
}
return result;
}
Aggregations