Skip to content

Commit

Permalink
use a better method for writing the example file
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmakila committed May 6, 2024
1 parent a0beb05 commit ae4b2ec
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,15 @@ private void loadFromResourceBundle() {
}

private void writeExampleTranslationsToDisk() {
Properties properties = new Properties();
// Extract all key-value pairs from the ResourceBundle
Enumeration<String> keys = this.defaultBundle.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
String value = this.defaultBundle.getString(key);
properties.setProperty(key, value);
}
List<String> lines = new ArrayList<>();
this.defaultBundle.getKeys().asIterator().forEachRemaining(key -> {
lines.add(key + "=" + this.defaultBundle.getString(key));
});
Collections.sort(lines);

try (OutputStream outputStream = new FileOutputStream(this.translationsDirectory.resolve("messages_example.properties").toFile())) {
Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
properties.store(writer, null);
try {
Files.write(this.translationsDirectory.resolve("messages_example.properties"), lines);
} catch (IOException e) {
this.logger.warn("Error saving example translation file", e);
}
Expand Down

0 comments on commit ae4b2ec

Please sign in to comment.