Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Locale: add setting for custom names for localization files
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Oct 7, 2023
1 parent 34cb268 commit 20b2ade
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/main/java/net/flectone/managers/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ private static void loadLocale(boolean needMigrate) {
FYamlConfiguration ruLocale = load(languagesPath + "ru.yml");
FYamlConfiguration enLocale = load(languagesPath + "en.yml");

String customLocaleName = config.getString("language");
FYamlConfiguration customLocale = switch (customLocaleName) {
case "ru" -> ruLocale;
case "en" -> enLocale;
default -> load(languagesPath + customLocaleName + ".yml");
};

if (customLocale == null) {
customLocale = enLocale;
}

if (needMigrate) {
migrate(ruLocale);
migrate(enLocale);
migrate(customLocale);
}

locale = switch (config.getString("language")) {
case "ru" -> ruLocale;
default -> enLocale;
};
locale = customLocale;
}

private static void loadIcons() {
Expand All @@ -68,14 +77,15 @@ private static void loadIcons() {

public static FYamlConfiguration load(String filePath) {
File file = new File(dataFolder + filePath);

if(!file.exists()) Main.getInstance().saveResource(filePath, false);

FYamlConfiguration fileConfiguration = new FYamlConfiguration(file, filePath);
FYamlConfiguration fileConfiguration = null;

try {
if (!file.exists()) Main.getInstance().saveResource(filePath, false);

fileConfiguration = new FYamlConfiguration(file, filePath);
fileConfiguration.save(file);
} catch (IOException exception) {

} catch (IOException | IllegalArgumentException exception) {
Main.warning("Failed to save " + filePath + " file");
exception.printStackTrace();
}
Expand Down

0 comments on commit 20b2ade

Please sign in to comment.