Package dev.orne.i18n
Class I18nResourcesString
java.lang.Object
dev.orne.i18n.I18nResourcesString
- All Implemented Interfaces:
I18nString,Serializable
@API(status=STABLE,
since="0.1")
public class I18nResourcesString
extends Object
implements I18nString
Implementation of
I18nString based on I18nResources.
The class supports providing arguments to be used when computing the
resulting texts for the different languages.
As the I18N resources formatting depends of the underlying implementation
the default text will be formatted with MessageFormat passing the
configured arguments, if any.
- Since:
- 0.1
- Version:
- 1.0, 2021-01
- Author:
- (w) Iker Hernaez
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder ofI18nResourcesStringinstances. -
Constructor Summary
ConstructorsConstructorDescriptionI18nResourcesString(String resources, @NotNull String defaultMessage, @NotNull String[] codes, Serializable... arguments) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescription@NotNull I18nStringMapasMap()Returns this instance represented as anI18nStringMapinstance.booleanstatic I18nResourcesString.BuilderforDefault(@NotNull String defaultMessage) Creates a builder of a new instance with the specified default text.get()Returns the text for the current language.Returns the text for the specified language, or the default text if no translation is available.Returns the text for language of the specified locale, or the default text if no translation is available.@NotNull Serializable[]Returns the text arguments, applied to resolved text or default text.@NotNull String[]getCodes()Returns the I18N text codes, in order of priority.@NotNull StringReturns the unformatted default text.@NotNull StringReturns the formatted default text.Returns the key of the I18N resources to use.inthashCode()booleanisEquivalent(I18nString obj) Returnstrueif the specifiedI18nStringis equivalent to this instance.@NotNull StringtoString()
-
Constructor Details
-
I18nResourcesString
public I18nResourcesString(String resources, @NotNull @NotNull String defaultMessage, @NotNull @NotNull String[] codes, Serializable... arguments) Creates a new instance.- Parameters:
resources- The I18N resources to use. Ifnullwill use default onesdefaultMessage- The default textcodes- The I18N text codes, in order of priorityarguments- The text arguments, applied to resolved text or default text
-
-
Method Details
-
forDefault
Creates a builder of a new instance with the specified default text.The text will be formatted with
MessageFormatpassing the configured arguments.- Parameters:
defaultMessage- The default text- Returns:
- The new instance builder
- See Also:
-
getI18nResourcesKey
Returns the key of the I18N resources to use. Ifnulldefault ones will be used.- Returns:
- The key of the I18N resources to use
-
getDefaultText
Returns the unformatted default text.- Returns:
- The unformatted default text
-
getFormattedDefaultText
Returns the formatted default text.- Returns:
- The formatted default text
-
getCodes
Returns the I18N text codes, in order of priority.- Returns:
- The I18N text codes
-
getArguments
Returns the text arguments, applied to resolved text or default text.- Returns:
- The text arguments
-
get
Returns the text for the current language.- Specified by:
getin interfaceI18nString- Returns:
- The text for the current language
-
get
Returns the text for the specified language, or the default text if no translation is available.- Specified by:
getin interfaceI18nString- Parameters:
language- The language of the requested text- Returns:
- The text for the specified language
-
get
Returns the text for language of the specified locale, or the default text if no translation is available.- Specified by:
getin interfaceI18nString- Parameters:
locale- The language of the requested text- Returns:
- The text for the specified language
-
hashCode
public int hashCode() -
equals
-
isEquivalent
Returnstrueif the specifiedI18nStringis equivalent to this instance.- If
otherisnullreturnsfalse. - If
otheris of the same type callsequals(). - Otherwise checks that the translations for current language of both instances are equal.
- Specified by:
isEquivalentin interfaceI18nString- Parameters:
obj- The instance to compare against- Returns:
- If both instances are equivalent
- If
-
asMap
Returns this instance represented as anI18nStringMapinstance.- Specified by:
asMapin interfaceI18nString- Returns:
- This instance represented as an
I18nStringMapinstance
-
toString
-