diff --git a/src/main/java/com/enderio/core/common/Lang.java b/src/main/java/com/enderio/core/common/Lang.java index 4aa305f..7d3a1b2 100644 --- a/src/main/java/com/enderio/core/common/Lang.java +++ b/src/main/java/com/enderio/core/common/Lang.java @@ -1,17 +1,19 @@ package com.enderio.core.common; -import lombok.AllArgsConstructor; import lombok.Getter; import net.minecraft.util.StatCollector; -@AllArgsConstructor @Getter public class Lang { private static final String REGEX = "\\" + '|'; public static final char CHAR = '|'; - private String locKey; + private final String prefix; + + public Lang(String locKey) { + this.prefix = locKey.concat("."); + } /** * Adds the stored prefix to this string, separating with a period. Using this @@ -23,7 +25,7 @@ public class Lang { * @return The full string */ public String addPrefix(String suffix) { - return locKey + "." + suffix; + return prefix.concat(suffix); } /** @@ -33,18 +35,27 @@ public class Lang { * @param unloc * The unlocalized string. * @param args - * The args to format the localized text withi. + * The args to format the localized text with. * * @return A localized string. */ public String localize(String unloc, Object... args) { - // Compat for old EIO code - if (args.length == 1 && args[0] instanceof Boolean && !((Boolean) args[0]).booleanValue()) { - return localizeExact(unloc); - } return localizeExact(addPrefix(unloc), args); } + /** + * Localizes the string passed, first appending the prefix stored in this + * instance of the class. + * + * @param unloc + * The unlocalized string. + * + * @return A localized string. + */ + public String localize(String unloc) { + return localizeExact(addPrefix(unloc)); + } + /** * Ignores the prefix stored in this instance of the class and localizes the * raw string passed. @@ -52,7 +63,7 @@ public class Lang { * @param unloc * The unlocalized string. * @param args - * The args to format the localized text withi. + * The args to format the localized text with. * * @return A localized string. */ @@ -60,17 +71,41 @@ public class Lang { return StatCollector.translateToLocalFormatted(unloc, args); } + /** + * Ignores the prefix stored in this instance of the class and localizes the + * raw string passed. + * + * @param unloc + * The unlocalized string. + * + * @return A localized string. + */ + public String localizeExact(String unloc) { + return StatCollector.translateToLocal(unloc); + } + /** * Splits the localized text on "|" into a String[]. * * @param unloc * The unlocalized string. * @param args - * The args to format the localized text withi. + * The args to format the localized text with. * @return A localized list of strings. */ public String[] localizeList(String unloc, String... args) { - return splitList(localize(unloc, true, args)); + return splitList(localize(unloc, (Object[]) args)); + } + + /** + * Splits the localized text on "|" into a String[]. + * + * @param unloc + * The unlocalized string. + * @return A localized list of strings. + */ + public String[] localizeList(String unloc) { + return splitList(localize(unloc)); } /**