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,36 +126,42 @@ public class Lang {
public void loadLang() throws InvalidConfigurationException, IOException { 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 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"); 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>(); LinkedHashMap<String, String> allStrings = new LinkedHashMap<String, String>();
FileConfiguration config; if (langFile.exists()) {
FileConfiguration config_new; FileConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), "UTF-8"));
if (langFile.exists() && langFile_new.exists()) { FileConfiguration config_new = null;
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), "UTF-8")); if (exists_new) {
config_new = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile_new), "UTF-8")); config_new = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile_new), "UTF-8"));
//Load user's lang file and determine new strings }
// Load user's lang file and determine new strings
for (String key : config.getKeys(false)) { for (String key : config.getKeys(false)) {
allStrings.put(key, config.getString(key)); allStrings.put(key, config.getString(key));
config_new.set(key, null); if (exists_new) {
} config_new.set(key, null);
//Add new strings and notify user
for (String key : config_new.getKeys(false)) {
String value = config_new.getString(key);
if (value != null) {
allStrings.put(key, value);
plugin.getLogger().warning("There are new language phrases in /lang/" + iso + "/strings_new.yml for the current version!"
+ " You must transfer them to, or regenerate, strings.yml to remove this warning!");
} }
} }
config_new.options().header("Below are any new strings for your current version of Quests! Transfer them to the strings.yml of the" // 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) {
allStrings.put(key, value);
plugin.getLogger().warning("There are new language phrases in /lang/" + iso + "/strings_new.yml for the current version!"
+ " You must transfer them to, or regenerate, strings.yml to remove this warning!");
}
}
config_new.options().header("Below are any new strings for your current version of Quests! Transfer them to the strings.yml of the"
+ " same folder to stay up-to-date and suppress console warnings."); + " same folder to stay up-to-date and suppress console warnings.");
config_new.options().copyHeader(true); config_new.options().copyHeader(true);
config_new.save(langFile_new); config_new.save(langFile_new);
}
} else { } else {
plugin.getLogger().severe("Failed loading lang files for " + iso + " because they were not found. Using default en-US"); 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("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"); plugin.getLogger().info("For help, visit https://github.com/FlyingPikachu/Quests/wiki/Casual-%E2%80%90-Translations");
iso = "en-US"; 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)) { for (String key : config.getKeys(false)) {
allStrings.put(key, config.getString(key)); allStrings.put(key, config.getString(key));
} }