- All Superinterfaces:
io.github.mmm.base.i18n.Localizable
,io.github.mmm.base.i18n.LocalizableObject
public interface NlsMessage
extends io.github.mmm.base.i18n.Localizable
This is the interface for an internationalized message. It stores an
The format of the
To specify
internationalized-message
separated from language independent arguments
. This approach ensures
that the message is always available in the internationalized language (should be English) while it still allows to
translate
the message to a native language. For an introduction first read
here
The format of the
internationalized-message
is similar to
MessageFormat
. This allows to migrate existing code from MessageFormat
to
NlsMessage
easily. However, there are some advanced features available. While using numbers to identify the
arguments
is a maintenance-hell for large messages, this solution is using
named arguments
(keys
) that should be
self-explanatory. Further, there is also support for additional styles as well as
Justification
. See NlsVariable
for the
specification of the argument syntax.To specify
NlsMessage
s you create an NlsBundle
per module.
For the term internationalization usually the shortcut i18n is used.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The prefix appended to themessage
if the localization (translation) failed.Fields inherited from interface io.github.mmm.base.i18n.Localizable
BUNDLE_PREFIX
-
Method Summary
Modifier and TypeMethodDescriptiondefault Object
getArgument
(String key) This method gets the internationalized message what is the actual message template for theroot locale
without resolving itsarguments
.default String
getLocalizedMessage
(Locale locale) This method gets the resolved and localized message.
First it will translate theinternationalized message
to the givenLocale
.Methods inherited from interface io.github.mmm.base.i18n.Localizable
getLocalizedMessage, getLocalizedMessage, getMessage, toLocalizable
-
Field Details
-
LOCALIZATION_FAILURE_PREFIX
The prefix appended to themessage
if the localization (translation) failed.- See Also:
-
-
Method Details
-
getInternationalizedMessage
String getInternationalizedMessage()This method gets the internationalized message what is the actual message template for theroot locale
without resolving itsarguments
.- Returns:
- the message for internationalization (e.g.
"Welcome {name}!"
). - See Also:
-
getArgument
- Specified by:
getArgument
in interfaceio.github.mmm.base.i18n.Localizable
- See Also:
-
getArguments
NlsArguments getArguments()- Returns:
- the dynamic
NlsArguments
to fill into the message after localization. - See Also:
-
getLocalizedMessage
This method gets the resolved and localized message.
First it will translate theinternationalized message
to the givenLocale
. If this fails for whatever reason, theinternationalized message
is used as fallback.
Then this message gets resolved by replacing thevariables
with their accordingarguments
.
Example:
We assume theinternationalized message
is"Welcome {name}!"
and theargument
with thekey
"name"
has thevalue
"Joelle"
. After translation toLocale.GERMAN
the message may be"Willkommen {name}!"
. This results in the resolved message"Willkommen Joelle!"
. If the German localization was not present or has a syntax error, theroot locale
is used as fallback resulting in"Welcome Joelle!"
.- Specified by:
getLocalizedMessage
in interfaceio.github.mmm.base.i18n.Localizable
- See Also:
-
getDescriptor
NlsMessageDescriptor getDescriptor()- Returns:
- the
NlsMessageDescriptor
.
-