package io.github.jacobmarshall.meloooncensor.lang;

import io.github.jacobmarshall.meloooncensor.config.Configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Translation {

    public static final Translation DEFAULT_TRANSLATION = new Translation(Configuration.DEFAULT_LANGUAGE, false);

    private boolean allowFallback;
    protected String language;
    protected Properties translations;

    public Translation (String language) {
        this(language, true);
    }

    private Translation (String language, boolean allowFallback) {
        this.language = language;
        this.translations = getTranslations(language);
        this.allowFallback = allowFallback;
    }

    public String getText (String key) {
        return this.translations.getProperty(key, this.allowFallback ?
            DEFAULT_TRANSLATION.getText(key) : "i18n:" + key);
    }

    private static Properties getTranslations (String language) {
        Properties properties = new Properties();
        InputStream inputStream = Translation.class.getResourceAsStream("/lang/" + language + ".properties");

        try {
            properties.load(inputStream);
        } catch (IOException err) {
            // Ignore (load the defaults)
        }

        return properties;
    }

}

@@ -785,22 +785,29 @@
         
-return
+String text =
  this.tr
@@ -917,16 +917,204 @@
  + key);
+%0A%0A        try %7B%0A            text = new String(text.getBytes(%22ISO-8859-1%22), %22UTF-8%22);%0A        %7D catch(Exception e) %7B%0A            // Ignore, keep old encoding%0A        %7D%0A%0A        return text;
 %0A    %7D%0A%0A

Fix encoding issue with extended character set