Skip to content

Commit 77974a9

Browse files
committed
Improve ukrainian translations.
1 parent 604c293 commit 77974a9

File tree

2 files changed

+6068
-2988
lines changed

2 files changed

+6068
-2988
lines changed

src/main/java/com/github/nosql/Nosql.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,45 @@ private static void processCommandLine(CommandLine cmd) throws Exception {
110110
} catch (Exception ex) {
111111
System.out.println(file.getPath() + " - " + ex.getMessage());
112112
}
113-
}
113+
} else if ("jsontoxml".equals(mode)) {
114+
File file = new File(sourceFileOrPath);
115+
File fileEn = new File(sourceFileOrPath.replaceFirst("\\.xml$", "-en.json"));
116+
File fileDe = new File(sourceFileOrPath.replaceFirst("\\.xml$", "-de.json"));
117+
File fileRu = new File(sourceFileOrPath.replaceFirst("\\.xml$", "-ru.json"));
118+
File fileUa = new File(sourceFileOrPath.replaceFirst("\\.xml$", "-ua.json"));
119+
try {
120+
final byte[] bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath(), new String[0]));
121+
String text = new String(removeBom(bytes), StandardCharsets.UTF_8);
122+
Map<String, Object> result = (Map<String, Object>) Xml.fromXml(text);
123+
List<Map<String, Object>> texts = (List<Map<String, Object>>) U.get(result, "document.texts.text");
124+
125+
final byte[] bytesEn = Files.readAllBytes(Paths.get(fileEn.getAbsolutePath(), new String[0]));
126+
String textEn = new String(bytesEn, StandardCharsets.UTF_8);
127+
final byte[] bytesDe = Files.readAllBytes(Paths.get(fileDe.getAbsolutePath(), new String[0]));
128+
String textDe = new String(bytesDe, StandardCharsets.UTF_8);
129+
final byte[] bytesRu = Files.readAllBytes(Paths.get(fileRu.getAbsolutePath(), new String[0]));
130+
String textRu = new String(bytesRu, StandardCharsets.UTF_8);
131+
final byte[] bytesUa = Files.readAllBytes(Paths.get(fileUa.getAbsolutePath(), new String[0]));
132+
String textUa = new String(bytesUa, StandardCharsets.UTF_8);
133+
List<Map<String, Object>> resultEn = (List<Map<String, Object>>) Json.fromJson(textEn);
134+
List<Map<String, Object>> resultDe = (List<Map<String, Object>>) Json.fromJson(textDe);
135+
List<Map<String, Object>> resultRu = (List<Map<String, Object>>) Json.fromJson(textRu);
136+
List<Map<String, Object>> resultUa = (List<Map<String, Object>>) Json.fromJson(textUa);
137+
int index = 0;
138+
for (Map<String, Object> textItem : texts) {
139+
textItem.put("-id", resultEn.get(index).get("-id"));
140+
textItem.put("en", resultEn.get(index).get("en"));
141+
textItem.put("de", resultDe.get(index).get("de"));
142+
textItem.put("ru", resultRu.get(index).get("ru"));
143+
textItem.put("ua", resultUa.get(index).get("ua"));
144+
index += 1;
145+
}
146+
final Path pathTarget = Paths.get("", new String[] { targetFileOrPath });
147+
Files.write(pathTarget, Xml.toXml(result).getBytes(StandardCharsets.UTF_8));
148+
} catch (Exception ex) {
149+
System.out.println(file.getPath() + " - " + ex.getMessage());
150+
}
151+
}
114152
}
115153

116154
private static byte[] removeBom(byte[] bytes) {

0 commit comments

Comments
 (0)