Attempt to populate lang even if _new file is missing, fixes #907

This commit is contained in:
PikaMug 2019-08-12 01:17:23 -04:00
parent 879fb969c9
commit bf1f39cbe5

View File

@ -126,18 +126,23 @@ public class Lang {
public void loadLang() throws InvalidConfigurationException, IOException {
File langFile = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + iso + File.separator + "strings.yml");
File langFile_new = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + iso + File.separator + "strings_new.yml");
boolean exists_new = langFile_new.exists();
LinkedHashMap<String, String> allStrings = new LinkedHashMap<String, String>();
FileConfiguration config;
FileConfiguration config_new;
if (langFile.exists() && langFile_new.exists()) {
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), "UTF-8"));
if (langFile.exists()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), "UTF-8"));
FileConfiguration config_new = null;
if (exists_new) {
config_new = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile_new), "UTF-8"));
}
// Load user's lang file and determine new strings
for (String key : config.getKeys(false)) {
allStrings.put(key, config.getString(key));
if (exists_new) {
config_new.set(key, null);
}
}
// Add new strings and notify user
if (exists_new) {
for (String key : config_new.getKeys(false)) {
String value = config_new.getString(key);
if (value != null) {
@ -150,12 +155,13 @@ public class Lang {
+ " same folder to stay up-to-date and suppress console warnings.");
config_new.options().copyHeader(true);
config_new.save(langFile_new);
}
} else {
plugin.getLogger().severe("Failed loading lang files for " + iso + " because they were not found. Using default en-US");
plugin.getLogger().info("If the plugin has not generated language files, ensure Quests has write permissions");
plugin.getLogger().info("For help, visit https://github.com/FlyingPikachu/Quests/wiki/Casual-%E2%80%90-Translations");
iso = "en-US";
config = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("strings.yml"), "UTF-8"));
FileConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("strings.yml"), "UTF-8"));
for (String key : config.getKeys(false)) {
allStrings.put(key, config.getString(key));
}