Anzeige von Areas aktualisiert
This commit is contained in:
@@ -14,7 +14,8 @@ import javafx.scene.layout.*;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class AreaEditorView extends BorderPane {
|
||||
|
||||
@@ -57,6 +58,7 @@ public class AreaEditorView extends BorderPane {
|
||||
current = saved;
|
||||
reloading = false;
|
||||
persist();
|
||||
writeDefaultLocalisationIfAbsent(saved.id());
|
||||
}
|
||||
|
||||
// ── Form panel ────────────────────────────────────────────────────────────
|
||||
@@ -229,6 +231,53 @@ public class AreaEditorView extends BorderPane {
|
||||
catch (IOException e) { areas.clear(); }
|
||||
}
|
||||
|
||||
// ── Localisation defaults ──────────────────────────────────────────────────
|
||||
|
||||
private void writeDefaultLocalisationIfAbsent(String fullId) {
|
||||
if (fullId == null || fullId.isBlank()) return;
|
||||
String shortId = fullId.startsWith(PREFIX) ? fullId.substring(PREFIX.length()) : fullId;
|
||||
if (shortId.isBlank()) return;
|
||||
String key = fullId + ".name";
|
||||
String defaultName = Character.toUpperCase(shortId.charAt(0)) + shortId.substring(1);
|
||||
|
||||
Path langSrc = ProjectRoot.resolve("blight-lang", "src", "main", "resources", "lang");
|
||||
Path[] langMirrors = {
|
||||
ProjectRoot.resolve("blight-lang", "bin", "main", "lang"),
|
||||
ProjectRoot.resolve("blight-lang", "build", "resources", "main", "lang"),
|
||||
};
|
||||
for (String locale : new String[]{"de", "en"}) {
|
||||
Path src = langSrc.resolve("messages_" + locale + ".properties");
|
||||
try {
|
||||
if (appendKeyIfAbsent(src, key, defaultName)) {
|
||||
for (Path mirrorDir : langMirrors) {
|
||||
Path mirror = mirrorDir.resolve("messages_" + locale + ".properties");
|
||||
if (Files.exists(mirror)) {
|
||||
Files.copy(src, mirror, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// non-critical
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns true if the key was absent and has been appended. */
|
||||
private static boolean appendKeyIfAbsent(Path file, String key, String value) throws IOException {
|
||||
if (!Files.exists(file)) return false;
|
||||
String needle = key + "=";
|
||||
String needleSpace = key + " =";
|
||||
for (String line : Files.readAllLines(file, StandardCharsets.UTF_8)) {
|
||||
String s = line.stripLeading();
|
||||
if (s.startsWith(needle) || s.startsWith(needleSpace)) return false;
|
||||
}
|
||||
String existing = Files.readString(file, StandardCharsets.UTF_8);
|
||||
String sep = existing.endsWith("\n") ? "" : "\n";
|
||||
Files.writeString(file, existing + sep + key + "=" + value + "\n",
|
||||
StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static Label sectionTitle(String text) {
|
||||
|
||||
Reference in New Issue
Block a user