Class EnumNameLocalizer

java.lang.Object
org.ka2ddo.yaac.util.EnumNameLocalizer

public class EnumNameLocalizer extends Object
This class provides a generalized mapping of Java enum constants to localized name strings without requiring the enum definitions to know about the source of the localized names.
Author:
Andrew Pavlin, KA2DDO
  • Method Details

    • registerEnum

      public static void registerEnum(Class<? extends Enum> clazz, String resourcePrefix)
      Register an entire enum class using the specified prefix when building resource names for localized string lookups.
      Parameters:
      clazz - Enum class whose elements should have localized Strings loaded
      resourcePrefix - String prefix (including any trailing '.') to prefix the Enum values' name() value for looking up resource Strings (null means use the simple class name plus a '.')
      See Also:
    • registerEnum

      public static void registerEnum(Class<? extends Enum> clazz, String resourcePrefix, EnumNameLocalizer.Type transType)
      Register an entire enum class using the specified prefix when building resource names for localized string lookups.
      Parameters:
      clazz - Enum class whose elements should have localized Strings loaded
      resourcePrefix - String prefix (including any trailing '.') to prefix the Enum values' name() value for looking up resource Strings (null means use the simple class name plus a '.')
      transType - Type of translation to store
      See Also:
    • getLocalizedName

      public static String getLocalizedName(Enum e)
      Look up the localized display string for an enumeration.
      Parameters:
      e - Enum value to look up
      Returns:
      localized String display name (if defined in resource bundles), falling back to Enum.name() if not known, or null if null enum value is passed
    • getLocalizedName

      public static String getLocalizedName(Enum e, EnumNameLocalizer.Type transType)
      Look up the localized display string for an enumeration.
      Parameters:
      e - Enum value to look up
      transType - Type of translation to look up
      Returns:
      localized String display name (if defined in resource bundles), falling back to Enum.name() if not known, or null if null enum value is passed
    • getLocalizedNames

      public static String[] getLocalizedNames(Class<? extends Enum> clazz, EnumNameLocalizer.Type transType)
      Look up all the localized display strings for all values of an enumeration.
      Parameters:
      clazz - Enum class to look up localized names
      transType - Type of translation to look up
      Returns:
      localized String display name