Package org.ka2ddo.yaac.util
Class EnumNameLocalizer
java.lang.Object
org.ka2ddo.yaac.util.EnumNameLocalizer
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum of different types of localizations for an Enum value. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Look up the localized display string for an enumeration.static String
getLocalizedName
(Enum e, EnumNameLocalizer.Type transType) Look up the localized display string for an enumeration.static String[]
getLocalizedNames
(Class<? extends Enum> clazz, EnumNameLocalizer.Type transType) Look up all the localized display strings for all values of an enumeration.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.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.
-
Method Details
-
registerEnum
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 loadedresourcePrefix
- 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 loadedresourcePrefix
- 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
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
Look up the localized display string for an enumeration.- Parameters:
e
- Enum value to look uptransType
- 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 namestransType
- Type of translation to look up- Returns:
- localized String display name
-