Skip to content

Commit

Permalink
Read localization files recursively as CK3 does
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyers committed Jun 6, 2024
1 parent a9ad878 commit 876799f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions EU3_Scenario_Editor/src/editor/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@ public final class Text {
*/
public static void initText(FilenameResolver resolver, GameVersion version) throws FileNotFoundException, IOException {
File[] files = resolver.listFiles("localisation");
if (files == null)
files = resolver.listFiles("localization/english"); // CK3/V3 switched to American spelling and put each language in a separate folder
if (files == null) {
log.log(Level.WARNING, "Could not find localization files");
return;
}

Arrays.sort(files);

if (version.getTextFormat().equals("yaml"))
if (version.getTextFormat().equals("yaml")) {
log.log(Level.INFO, "Reading YAML text files");
processFilesYaml(files);
else
} else {
log.log(Level.INFO, "Reading CSV text files");
processFilesCsv(files);
}
}

private static void processFilesCsv(File[] files) throws FileNotFoundException, IOException {
log.log(Level.INFO, "Reading CSV text files");
for (File f : files) {
if (!f.getName().endsWith(".csv"))
continue; // Could use a FileFilter or FilenameFilter
Expand Down Expand Up @@ -93,8 +97,12 @@ private static void processFilesYaml(File[] files) throws FileNotFoundException,
// very naive implementation
// EU4 YAML files consist of a single node, defined in the first line
// so we skip that line and break everything else at a ":"
log.log(Level.INFO, "Reading YAML text files");
for (File f : files) {
if (f.isDirectory()) {
processFilesYaml(f.listFiles());
continue;
}

if (!f.getName().endsWith(".yml"))
continue; // Could use a FileFilter or FilenameFilter

Expand Down

0 comments on commit 876799f

Please sign in to comment.