Print how many changed translations alongside how many translations

This commit is contained in:
libraryaddict 2021-05-22 05:26:20 +12:00
parent 2902de50c2
commit dd4556824a

View File

@ -50,8 +50,9 @@ public enum TranslateType {
while (itel.hasNext()) { while (itel.hasNext()) {
Map.Entry<String, String> entry = itel.next(); Map.Entry<String, String> entry = itel.next();
if (!entry.getKey().equals(entry.getValue())) if (!entry.getKey().equals(entry.getValue())) {
continue; continue;
}
itel.remove(); itel.remove();
} }
@ -63,8 +64,7 @@ public enum TranslateType {
writer.close(); writer.close();
writer = null; writer = null;
} }
} } catch (IOException e) {
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -84,33 +84,28 @@ public enum TranslateType {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.options().pathSeparator(Character.toChars(0)[0]); config.options().pathSeparator(Character.toChars(0)[0]);
int diff = 0;
try { try {
config.load(getFile()); config.load(getFile());
int dupes = 0; int dupes = 0;
int diff = 0;
for (String key : config.getKeys(false)) { for (String key : config.getKeys(false)) {
String value = config.getString(key); String value = config.getString(key);
if (value == null) { if (value == null) {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().severe("Translation for " + name() + " has a null value for the key '" + key + "'");
.severe("Translation for " + name() + " has a null value for the key '" + key + "'");
} else { } else {
String newKey = DisguiseUtilities.translateAlternateColorCodes(key); String newKey = DisguiseUtilities.translateAlternateColorCodes(key);
if (translated.containsKey(newKey)) { if (translated.containsKey(newKey)) {
if (dupes++ < 5) { if (dupes++ < 5) {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().severe("Alert! Duplicate translation entry for " + key + " in " + name() + " translations!");
.severe("Alert! Duplicate translation entry for " + key + " in " + name() +
" translations!");
continue; continue;
} else { } else {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger()
.severe("Too many duplicated keys! It's likely that this file was mildly " + .severe("Too many duplicated keys! It's likely that this file was mildly " + "corrupted by a previous bug!");
"corrupted by a previous bug!"); DisguiseUtilities.getLogger().severe("Delete the file, or you can remove every line after the first " + "duplicate message!");
DisguiseUtilities.getLogger()
.severe("Delete the file, or you can remove every line after the first " +
"duplicate message!");
break; break;
} }
} }
@ -124,16 +119,14 @@ public enum TranslateType {
} }
if (diff > 0 && !DisguiseConfig.isUseTranslations()) { if (diff > 0 && !DisguiseConfig.isUseTranslations()) {
DisguiseUtilities.getLogger().info(diff + DisguiseUtilities.getLogger().info(diff + " translated strings, but translations has been disabled in config. Is this intended?");
" translated strings, but translations has been disabled in config. Is this intended?");
} }
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) { if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
DisguiseUtilities.getLogger().info("Loaded " + translated.size() + " translations for " + name()); DisguiseUtilities.getLogger().info("Loaded " + translated.size() + " translations for " + name() + " with " + diff + " changed");
} }
} }
@ -142,8 +135,9 @@ public enum TranslateType {
} }
public void save(String msg) { public void save(String msg) {
if (this != TranslateType.MESSAGES) if (this != TranslateType.MESSAGES) {
throw new IllegalArgumentException("Can't set no comment for '" + msg + "'"); throw new IllegalArgumentException("Can't set no comment for '" + msg + "'");
}
save(msg, null); save(msg, null);
} }
@ -172,34 +166,32 @@ public enum TranslateType {
writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n"); writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n");
if (this == TranslateType.MESSAGES) { if (this == TranslateType.MESSAGES) {
writer.write( writer.write("# %s is where text is inserted, look up printf format codes if you're interested\n");
"# %s is where text is inserted, look up printf format codes if you're interested\n");
} }
writer.write( writer.write("# To translate, follow this example 'Original Message': 'My New Message'\n# The Original" +
"# To translate, follow this example 'Original Message': 'My New Message'\n# The Original" + " Message is used as a yaml config key to get your new message!");
" Message is used as a yaml config key to get your new message!");
writer.write("\n# To use hex color codes, use <#hexcolor> where hexcolor is the 6 char code"); writer.write("\n# To use hex color codes, use <#hexcolor> where hexcolor is the 6 char code");
} }
} }
writer.write("\n" + (comment != null ? "# " + comment + "\n" : "") + "\"" + message + "\": \"" + message + writer.write("\n" + (comment != null ? "# " + comment + "\n" : "") + "\"" + message + "\": \"" + message + "\"\n");
"\"\n"); } catch (Exception ex) {
}
catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public String reverseGet(String translated) { public String reverseGet(String translated) {
if (translated == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) if (translated == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) {
return translated; return translated;
}
String lowerCase = translated.toLowerCase(Locale.ENGLISH); String lowerCase = translated.toLowerCase(Locale.ENGLISH);
for (Map.Entry<String, String> entry : this.translated.entrySet()) { for (Map.Entry<String, String> entry : this.translated.entrySet()) {
if (!Objects.equals(entry.getValue().toLowerCase(Locale.ENGLISH), lowerCase)) if (!Objects.equals(entry.getValue().toLowerCase(Locale.ENGLISH), lowerCase)) {
continue; continue;
}
return entry.getKey(); return entry.getKey();
} }
@ -208,8 +200,9 @@ public enum TranslateType {
} }
public String get(String msg) { public String get(String msg) {
if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) {
return msg; return msg;
}
String toReturn = translated.get(msg); String toReturn = translated.get(msg);