Search in sources :

Example 1 with OrderedPropertiesBuilder

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);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with OrderedPropertiesBuilder

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonValue(com.badlogic.gdx.utils.JsonValue) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) JsonReader(com.badlogic.gdx.utils.JsonReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

OrderedPropertiesBuilder (com.bladecoder.engineeditor.common.NewOrderedProperties.OrderedPropertiesBuilder)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 InputStreamReader (java.io.InputStreamReader)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 JsonReader (com.badlogic.gdx.utils.JsonReader)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 IOException (java.io.IOException)1