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
Modifier and TypeClassDescriptionstatic class
Builder ofI18nResourcesString
instances. -
Constructor Summary
ConstructorDescriptionI18nResourcesString
(String resources, @NotNull String defaultMessage, @NotNull String[] codes, Serializable... arguments) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescription@NotNull I18nStringMap
asMap()
Returns this instance represented as anI18nStringMap
instance.boolean
static I18nResourcesString.Builder
forDefault
(@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 String
Returns the unformatted default text.@NotNull String
Returns the formatted default text.Returns the key of the I18N resources to use.int
hashCode()
boolean
isEquivalent
(I18nString obj) Returnstrue
if the specifiedI18nString
is equivalent to this instance.@NotNull String
toString()
-
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. Ifnull
will 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
MessageFormat
passing 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. Ifnull
default 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:
get
in 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:
get
in 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:
get
in interfaceI18nString
- Parameters:
locale
- The language of the requested text- Returns:
- The text for the specified language
-
hashCode
public int hashCode() -
equals
-
isEquivalent
Returnstrue
if the specifiedI18nString
is equivalent to this instance.- If
other
isnull
returnsfalse
. - If
other
is of the same type callsequals()
. - Otherwise checks that the translations for current language of both instances are equal.
- Specified by:
isEquivalent
in interfaceI18nString
- Parameters:
obj
- The instance to compare against- Returns:
- If both instances are equivalent
- If
-
asMap
Returns this instance represented as anI18nStringMap
instance.- Specified by:
asMap
in interfaceI18nString
- Returns:
- This instance represented as an
I18nStringMap
instance
-
toString
-