use of com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class I18NUtils method importTSV.
public static final void importTSV(String modelPath, String tsvFile, String chapterId, String defaultLocale) throws FileNotFoundException, IOException {
File inputFile = new File(tsvFile);
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), "UTF8"))) {
// get header
String line = br.readLine();
if (line != null) {
String[] langs = line.split(SEPARATOR);
NewOrderedProperties[] props = new NewOrderedProperties[langs.length - 1];
for (int i = 0; i < props.length; i++) {
OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
builder.withSuppressDateInComment(true);
props[i] = builder.build();
}
// get keys and texts
while ((line = br.readLine()) != null) {
String[] values = line.split(SEPARATOR);
if (values.length != langs.length) {
EditorLogger.error("Incorrect line in .tsv: " + line);
continue;
}
String key = values[0];
for (int i = 0; i < props.length; i++) {
String value = values[i + 1];
if (value != null)
value = value.replace("\\n", "\n");
props[i].setProperty(key, value);
}
}
// save properties
for (int i = 0; i < props.length; i++) {
String i18nFilename;
if (langs[i + 1].equals(defaultLocale)) {
i18nFilename = modelPath + "/" + chapterId + PROPERTIES_EXT;
} else {
i18nFilename = modelPath + "/" + chapterId + "_" + langs[i + 1] + PROPERTIES_EXT;
}
FileOutputStream os = new FileOutputStream(i18nFilename);
Writer out = new OutputStreamWriter(os, I18N.ENCODING);
props[i].store(out, null);
}
}
}
}
use of com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.
the class ModelTools method extractInkTexts.
public static void extractInkTexts(String story, String lang) throws IOException {
String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
StringBuilder sb = new StringBuilder();
try {
String line = br.readLine();
// Replace the BOM mark
if (line != null)
line = line.replace('\uFEFF', ' ');
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
} finally {
br.close();
}
JsonValue root = new JsonReader().parse(sb.toString());
StringBuilder tsvString = new StringBuilder();
OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
builder.withSuppressDateInComment(true);
NewOrderedProperties prop = builder.build();
extractInkTextsInternal(root, tsvString, prop);
FileUtils.writeStringToFile(new File(file + ".tsv"), tsvString.toString());
String json = root.toJson(OutputType.json);
FileUtils.writeStringToFile(new File(file + ".new"), json);
FileUtils.copyFile(new File(file), new File(file + ".old"));
FileUtils.copyFile(new File(file + ".new"), new File(file));
new File(file + ".new").delete();
try {
String file2 = file.substring(0, file.length() - EngineAssetManager.INK_EXT.length());
if (lang.equals("default"))
file2 += "-ink.properties";
else
file2 += "-ink" + "_" + lang + ".properties";
FileOutputStream os = new FileOutputStream(file2);
Writer out = new OutputStreamWriter(os, I18N.ENCODING);
prop.store(out, null);
} catch (IOException e) {
EditorLogger.error("ERROR WRITING BUNDLE: " + file + ".properties");
}
// Ctx.project.setModified();
}
Aggregations