From 895bdbbe7f1e4a907bd779bea5a8bc8c47f765f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Ha=C3=9Flinger?= Date: Fri, 23 Apr 2021 22:32:26 +0200 Subject: [PATCH] Fix properties encoding / issue #6 Properties files should be saved by using the charset provided by the file. --- .../io/implementation/PropertiesTranslatorIO.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/marhali/easyi18n/io/implementation/PropertiesTranslatorIO.java b/src/main/java/de/marhali/easyi18n/io/implementation/PropertiesTranslatorIO.java index 41161df..c113a44 100644 --- a/src/main/java/de/marhali/easyi18n/io/implementation/PropertiesTranslatorIO.java +++ b/src/main/java/de/marhali/easyi18n/io/implementation/PropertiesTranslatorIO.java @@ -11,10 +11,7 @@ import de.marhali.easyi18n.util.TranslationsUtil; import org.jetbrains.annotations.NotNull; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; +import java.io.*; import java.util.*; import java.util.function.Consumer; @@ -46,7 +43,7 @@ public class PropertiesTranslatorIO implements TranslatorIO { for (VirtualFile file : files) { locales.add(file.getNameWithoutExtension()); Properties properties = new Properties(); - properties.load(new InputStreamReader(file.getInputStream(), file.getCharset()));; + properties.load(new InputStreamReader(file.getInputStream(), file.getCharset())); readProperties(file.getNameWithoutExtension(), properties, nodes); } @@ -70,8 +67,9 @@ public class PropertiesTranslatorIO implements TranslatorIO { String fullPath = directoryPath + "/" + locale + "." + FILE_EXTENSION; VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(fullPath)); - ByteArrayOutputStream content = new ByteArrayOutputStream(); + StringWriter content = new StringWriter(); properties.store(content, "I18n " + locale + " keys"); + file.setBinaryContent(content.toString().getBytes(file.getCharset())); }