Use correct charset on io operations

Always use the charset provided by the file
This commit is contained in:
Marcel Haßlinger 2021-03-15 18:35:56 +01:00
parent 32c2eb20b4
commit 976458ac33
2 changed files with 4 additions and 6 deletions

View File

@ -44,7 +44,7 @@ public class JsonTranslatorIO implements TranslatorIO {
try {
for(VirtualFile file : files) {
locales.add(file.getNameWithoutExtension());
JsonObject tree = JsonParser.parseReader(new InputStreamReader(file.getInputStream())).getAsJsonObject();
JsonObject tree = JsonParser.parseReader(new InputStreamReader(file.getInputStream(), file.getCharset())).getAsJsonObject();
readTree(file.getNameWithoutExtension(), tree, nodes);
}
@ -71,7 +71,7 @@ public class JsonTranslatorIO implements TranslatorIO {
String fullPath = directoryPath + "/" + locale + "." + FILE_EXTENSION;
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(fullPath));
file.setBinaryContent(gson.toJson(content).getBytes());
file.setBinaryContent(gson.toJson(content).getBytes(file.getCharset()));
}
// Successfully saved
@ -133,8 +133,6 @@ public class JsonTranslatorIO implements TranslatorIO {
Map<String, String> messages = leafNode.getValue();
messages.put(locale, entry.getValue().getAsString());
leafNode.setValue(messages);
System.out.println("updated key + " + key + "de locale: " + messages.get("locale-de"));
}
}
}

View File

@ -46,7 +46,7 @@ public class PropertiesTranslatorIO implements TranslatorIO {
for (VirtualFile file : files) {
locales.add(file.getNameWithoutExtension());
Properties properties = new Properties();
properties.load(new InputStreamReader(file.getInputStream()));;
properties.load(new InputStreamReader(file.getInputStream(), file.getCharset()));;
readProperties(file.getNameWithoutExtension(), properties, nodes);
}
@ -72,7 +72,7 @@ public class PropertiesTranslatorIO implements TranslatorIO {
ByteArrayOutputStream content = new ByteArrayOutputStream();
properties.store(content, "I18n " + locale + " keys");
file.setBinaryContent(content.toByteArray());
file.setBinaryContent(content.toString().getBytes(file.getCharset()));
}
// Successfully saved