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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLocalizedEnumProvider
(String keySuffix, String defaultValue) Creates an instance. -
Method Summary
Modifier and TypeMethodDescriptiongetDefaultString
(T value) Returns the default string to use for the given enum constant, if localization is not available.getLocalizedString
(T value) Returns localized string for the given enum value.getLocalizedString
(T value, boolean plural) Returns localized string for the given enum value.getLocalizedString
(T value, String keySuffix) Returns localized string for the given enum value.getLocalizedString
(T value, String keySuffix, String defaultString) Returns localized string for the given enum value.Obtains string representation of a givenobject
specific to this provider.
-
Field Details
-
SINGULAR_SUFFIX
Standard singular key suffix.- See Also:
-
PLURAL_SUFFIX
Standard plural key suffix.- See Also:
-
ENUMS_PREFIX
Standard enum key prefix.- See Also:
-
SEPARATOR
Standard key part separator.- See Also:
-
-
Constructor Details
-
LocalizedEnumProvider
Creates an instance.- Parameters:
keySuffix
- suffix, may benull
.defaultValue
- default value, may benull
.
-
-
Method Details
-
getLocalizedString
Returns localized string for the given enum value.- Type Parameters:
T
- enum type.- Parameters:
value
- enum value (enum constant), may benull
.- Returns:
- localized string for the given enum value, or
the default string
. Nevernull
.
-
getLocalizedString
Returns localized string for the given enum value.- Type Parameters:
T
- enum type.- Parameters:
value
- enum value (enum constant), may benull
.plural
- whether to useplural
orsingular
key suffix.- Returns:
- localized string for the given enum value, or
the default string
. Nevernull
.
-
getLocalizedString
Returns localized string for the given enum value.- Type Parameters:
T
- enum type.- Parameters:
value
- enum value (enum constant), may benull
.keySuffix
- localization key suffix, may benull
.- Returns:
- localized string for the given enum value, or
the default string
. Nevernull
.
-
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 benull
.keySuffix
- localization key suffix, may benull
.defaultString
- default string to return if the localization is not found, may benull
.- Returns:
- localized string for the given enum value, or the
defaultString
.
-
getDefaultString
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 benull
.- Returns:
- the default string to use for the given enum constant, if localization is not available. It is
value.toString()
, ifvalue != null
, and an empty string otherwise. Never [@code null}.
-
getString
Description copied from interface:ILocalizationProvider
Obtains string representation of a givenobject
specific to this provider.- Specified by:
getString
in interfaceILocalizationProvider<T extends Enum<T>>
- Parameters:
object
- object to obtain string representation of. Should not benull
.- Returns:
- obtained string representation or
null
if no presentation available.
-