Class LocalizedEnumProvider<T extends Enum<T>>

java.lang.Object
com._1c.g5.v8.dt.common.localization.LocalizedEnumProvider<T>
All Implemented Interfaces:
ILocalizationProvider<T>

public class LocalizedEnumProvider<T extends Enum<T>> extends Object implements ILocalizationProvider<T>
Localization provider for Java language enums. Localization for enums must be contributed via the com._1c.g5.v8.dt.common.localization.bundles extension point. Their localization keys must be of the following format: enums|<simple-name>|<enum-constant>|<suffix>, where <simple-name> is the result of getClass().getSimpleName(), <enum-constant> is the enum constant name received via Enum.toString(), and <suffix> is an optional suffix. Two of the common suffixes are singular and plural.
  • Field Details

  • Constructor Details

    • LocalizedEnumProvider

      public LocalizedEnumProvider(String keySuffix, String defaultValue)
      Creates an instance.
      Parameters:
      keySuffix - suffix, may be null.
      defaultValue - default value, may be null.
  • Method Details

    • getLocalizedString

      public static <T extends Enum<T>> String getLocalizedString(T value)
      Returns localized string for the given enum value.
      Type Parameters:
      T - enum type.
      Parameters:
      value - enum value (enum constant), may be null.
      Returns:
      localized string for the given enum value, or the default string. Never null.
    • getLocalizedString

      public static <T extends Enum<T>> String getLocalizedString(T value, boolean plural)
      Returns localized string for the given enum value.
      Type Parameters:
      T - enum type.
      Parameters:
      value - enum value (enum constant), may be null.
      plural - whether to use plural or singular key suffix.
      Returns:
      localized string for the given enum value, or the default string. Never null.
    • getLocalizedString

      public static <T extends Enum<T>> String getLocalizedString(T value, String keySuffix)
      Returns localized string for the given enum value.
      Type Parameters:
      T - enum type.
      Parameters:
      value - enum value (enum constant), may be null.
      keySuffix - localization key suffix, may be null.
      Returns:
      localized string for the given enum value, or the default string. Never null.
    • getLocalizedString

      public static <T extends Enum<T>> String getLocalizedString(T value, String keySuffix, String defaultString)
      Returns localized string for the given enum value.
      Type Parameters:
      T - enum type.
      Parameters:
      value - enum value (enum constant), may be null.
      keySuffix - localization key suffix, may be null.
      defaultString - default string to return if the localization is not found, may be null.
      Returns:
      localized string for the given enum value, or the defaultString.
    • getDefaultString

      public static <T extends Enum<T>> String getDefaultString(T value)
      Returns the default string to use for the given enum constant, if localization is not available.
      Type Parameters:
      T - enum type.
      Parameters:
      value - enum value (enum constant), may be null.
      Returns:
      the default string to use for the given enum constant, if localization is not available. It is value.toString(), if value != null, and an empty string otherwise. Never [@code null}.
    • getString

      public String getString(T object)
      Description copied from interface: ILocalizationProvider
      Obtains string representation of a given object specific to this provider.
      Specified by:
      getString in interface ILocalizationProvider<T extends Enum<T>>
      Parameters:
      object - object to obtain string representation of. Should not be null.
      Returns:
      obtained string representation or null if no presentation available.