Makes translator color conversion configurable
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
This commit is contained in:
parent
f1ccee13c2
commit
5e8b13785d
@ -31,6 +31,7 @@ public final class Translator {
|
|||||||
private final List<TranslatableMessage> messageCategories = new ArrayList<>();
|
private final List<TranslatableMessage> messageCategories = new ArrayList<>();
|
||||||
private Map<TranslatableMessage, String> translatedMessages;
|
private Map<TranslatableMessage, String> translatedMessages;
|
||||||
private Map<TranslatableMessage, String> backupTranslatedMessages;
|
private Map<TranslatableMessage, String> backupTranslatedMessages;
|
||||||
|
private ColorConversion colorConversion = ColorConversion.RGB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers all translatable messages in the given message category
|
* Registers all translatable messages in the given message category
|
||||||
@ -44,6 +45,23 @@ public final class Translator {
|
|||||||
messageCategories.add(translatableMessage);
|
messageCategories.add(translatableMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color conversion to use for translated messages
|
||||||
|
*
|
||||||
|
* <p>See {@link net.knarcraft.knarlib.property.ColorConversion} and
|
||||||
|
* {@link net.knarcraft.knarlib.util.ColorHelper#translateColorCodes(String, ColorConversion)} for details, but
|
||||||
|
* basically, this allows setting which color codes should be converted, and which should not be.</p>
|
||||||
|
*
|
||||||
|
* @param colorConversion <p>The color conversion to be used</p>
|
||||||
|
*/
|
||||||
|
public void setColorConversion(ColorConversion colorConversion) {
|
||||||
|
if (colorConversion != null) {
|
||||||
|
this.colorConversion = colorConversion;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Color conversion cannot be null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the languages used by this translator
|
* Loads the languages used by this translator
|
||||||
*
|
*
|
||||||
@ -77,7 +95,7 @@ public final class Translator {
|
|||||||
} else {
|
} else {
|
||||||
translatedMessage = translatableMessage.toString();
|
translatedMessage = translatableMessage.toString();
|
||||||
}
|
}
|
||||||
return ColorHelper.translateColorCodes(translatedMessage, ColorConversion.RGB);
|
return ColorHelper.translateColorCodes(translatedMessage, colorConversion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,7 +133,8 @@ public final class Translator {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Bukkit.getLogger().log(Level.INFO, "Loading custom strings...");
|
Bukkit.getLogger().log(Level.INFO, "Loading custom strings...");
|
||||||
return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader(new FileInputStream(strings))));
|
return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader(
|
||||||
|
new FileInputStream(strings))));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Unable to load custom messages");
|
Bukkit.getLogger().log(Level.WARNING, "Unable to load custom messages");
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user