Search in sources :

Example 1 with OrderedPropertiesBuilder

use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.

the class I18NUtils method compare.

public static final void compare(String modelPath, final String chapterId, String defaultLocale, String destLocale) throws FileNotFoundException, IOException {
    File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
    File destChapter = new File(modelPath, chapterId + "_" + destLocale + PROPERTIES_EXT);
    OrderedProperties defaultProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    OrderedProperties destProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    defaultProp.load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
    destProp.load(new InputStreamReader(new FileInputStream(destChapter), I18N.ENCODING));
    // SEARCH FOR NOT EXISTING DEST KEYS
    for (Entry<String, String> e : defaultProp.entrySet()) {
        if (destProp.getProperty(e.getKey()) == null) {
            EditorLogger.error("Key not found in '" + destLocale + "' locale: " + e.getKey());
        }
    }
    // SEARCH FOR NOT EXISTING DEFAULT CHAPTER KEYS
    for (Entry<String, String> e : destProp.entrySet()) {
        if (defaultProp.getProperty(e.getKey()) == null) {
            EditorLogger.error("Key not found in default locale: " + e.getKey());
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with OrderedPropertiesBuilder

use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.

the class I18NUtils method exportTSV.

public static final void exportTSV(String modelPath, String outFile, final String chapterId, String defaultLocale) throws FileNotFoundException, IOException {
    File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
    File outputFile;
    if (outFile == null)
        outputFile = new File(modelPath, chapterId + TSV_EXT);
    else
        outputFile = new File(outFile);
    // 1. Find all chapter properties
    File[] files = new File(modelPath).listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File arg0, String arg1) {
            if (!arg1.endsWith(PROPERTIES_EXT) || !arg1.startsWith(chapterId + "_"))
                return false;
            return true;
        }
    });
    OrderedProperties[] props = new OrderedProperties[files.length + 1];
    props[0] = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    props[0].load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
    for (int i = 1; i < props.length; i++) {
        props[i] = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
        props[i].load(new InputStreamReader(new FileInputStream(files[i - 1]), I18N.ENCODING));
    }
    // WRITE THE OUTPUT FILE
    BufferedWriter writer = null;
    writer = new BufferedWriter(new FileWriter(outputFile));
    String lang = defaultLocale;
    writer.write("KEY");
    // write header
    for (int i = 0; i < props.length; i++) {
        if (i != 0)
            lang = files[i - 1].getName().substring(files[i - 1].getName().lastIndexOf('_') + 1, files[i - 1].getName().lastIndexOf('.'));
        writer.write(SEPARATOR + lang);
    }
    writer.write("\n");
    Set<Entry<String, String>> keySet = props[0].entrySet();
    for (Entry<String, String> e : keySet) {
        writer.write(e.getKey());
        for (OrderedProperties p : props) {
            if (p.getProperty(e.getKey()) == null) {
                writer.write(SEPARATOR + "**" + props[0].getProperty(e.getKey()).replace("\n", "\\n"));
                System.out.println("KEY NOT FOUND: " + e);
            } else {
                writer.write(SEPARATOR + p.getProperty(e.getKey()).replace("\n", "\\n"));
            }
        }
        writer.write("\n");
    }
    writer.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) FileWriter(java.io.FileWriter) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) FilenameFilter(java.io.FilenameFilter) Entry(java.util.Map.Entry) File(java.io.File)

Example 3 with OrderedPropertiesBuilder

use of com.bladecoder.engineeditor.common.OrderedProperties.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);
            OrderedProperties[] props = new OrderedProperties[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.OrderedProperties.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 4 with OrderedPropertiesBuilder

use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.

the class I18NUtils method sync.

public static final void sync(String modelPath, final String chapterId, String defaultLocale, String destLocale) throws FileNotFoundException, IOException {
    File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
    File destChapter = new File(modelPath, chapterId + "_" + destLocale + PROPERTIES_EXT);
    OrderedProperties defaultProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    OrderedProperties destProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    defaultProp.load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
    destProp.load(new InputStreamReader(new FileInputStream(destChapter), I18N.ENCODING));
    // SEARCH FOR NOT EXISTING DEST KEYS
    for (String key : defaultProp.stringPropertyNames()) {
        if (destProp.getProperty(key) == null) {
            System.out.println("ADDING Key not found in '" + destLocale + "' locale: " + key + "=" + defaultProp.getProperty(key));
            destProp.setProperty(key, "**" + defaultProp.getProperty(key));
        }
    }
    // SEARCH FOR NOT EXISTING DEFAULT CHAPTER KEYS
    for (String key : destProp.stringPropertyNames()) {
        if (defaultProp.getProperty(key) == null) {
            System.out.println("DELETE MANUALLY Key not found in default locale: " + key);
        }
    }
    // save dest .properties
    FileOutputStream os = new FileOutputStream(destChapter);
    Writer out = new OutputStreamWriter(os, I18N.ENCODING);
    destProp.store(out, destChapter.getName());
}
Also used : InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 5 with OrderedPropertiesBuilder

use of com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder in project bladecoder-adventure-engine by bladecoder.

the class I18NUtils method newLocale.

public static final void newLocale(String modelPath, final String chapterId, String defaultLocale, String newLocale) throws FileNotFoundException, IOException {
    File defaultChapter = new File(modelPath, chapterId + PROPERTIES_EXT);
    File newChapter = new File(modelPath, chapterId + "_" + newLocale + PROPERTIES_EXT);
    OrderedProperties defaultProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    OrderedProperties newProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering().build();
    defaultProp.load(new InputStreamReader(new FileInputStream(defaultChapter), I18N.ENCODING));
    for (Entry<String, String> e : defaultProp.entrySet()) {
        newProp.setProperty(e.getKey(), "**" + defaultProp.getProperty(e.getKey()));
    }
    // save new .properties
    FileOutputStream os = new FileOutputStream(newChapter);
    Writer out = new OutputStreamWriter(os, I18N.ENCODING);
    newProp.store(out, newChapter.getName());
}
Also used : InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

OrderedPropertiesBuilder (com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder)10 FileInputStream (java.io.FileInputStream)8 InputStreamReader (java.io.InputStreamReader)8 File (java.io.File)7 BufferedWriter (java.io.BufferedWriter)5 FileWriter (java.io.FileWriter)5 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 BufferedReader (java.io.BufferedReader)3 JsonReader (com.badlogic.gdx.utils.JsonReader)2 JsonValue (com.badlogic.gdx.utils.JsonValue)2 IOException (java.io.IOException)2 Lwjgl3Graphics (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics)1 Lwjgl3Window (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window)1 SerializationException (com.badlogic.gdx.utils.SerializationException)1 OrderedProperties (com.bladecoder.engineeditor.common.OrderedProperties)1 FilenameFilter (java.io.FilenameFilter)1 Entry (java.util.Map.Entry)1