-
- All Superinterfaces:
Localizable
,LocalizableObject
public interface NlsMessage extends Localizable
This is the interface for an internationalized message. It stores aninternationalized-message
separated from language independentarguments
. This approach ensures that the message is always available in the internationalized language (should be English) while it still allows totranslate
the message to a native language. For an introduction first readhere
The format of theinternationalized-message
is similar toMessageFormat
. This allows to migrate existing code fromMessageFormat
toNlsMessage
easily. However, there are some advanced features available. While using numbers to identify thearguments
is a maintenance-hell for large messages, this solution is usingnamed arguments
(keys
) that should be self-explanatory. Further, there is also support for additional styles as well asJustification
. SeeNlsVariable
for the specification of the argument syntax.
To specifyNlsMessage
s you create anNlsBundle
per module. For the term internationalization usually the shortcut i18n is used.- See Also:
NlsVariable
,NlsBundle
,NlsMessageFactory
,io.github.mmm.nls
-
-
Field Summary
Fields Modifier and Type Field Description static String
LOCALIZATION_FAILURE_PREFIX
The prefix appended to themessage
if the localization (translation) failed.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Object
getArgument(String key)
This method gets the language independent argument value for the givenkey
.NlsArguments
getArguments()
NlsMessageDescriptor
getDescriptor()
String
getInternationalizedMessage()
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 Detail
-
LOCALIZATION_FAILURE_PREFIX
static final String LOCALIZATION_FAILURE_PREFIX
The prefix appended to themessage
if the localization (translation) failed.- See Also:
- Constant Field Values
-
-
Method Detail
-
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:
NlsMessage
,getArguments()
,NlsVariable
-
getArgument
default Object getArgument(String key)
Description copied from interface:Localizable
This method gets the language independent argument value for the givenkey
.- Specified by:
getArgument
in interfaceLocalizable
- Parameters:
key
- is the name of the requested argument.- Returns:
- the argument value for the given key or
null
if NOT defined. - See Also:
NlsArguments.get(String)
,NlsVariable
-
getArguments
NlsArguments getArguments()
- Returns:
- the dynamic
NlsArguments
to fill into the message after localization. - See Also:
NlsArguments
,NlsVariable
-
getLocalizedMessage
default String getLocalizedMessage(Locale locale)
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 interfaceLocalizable
- Parameters:
locale
- is the locale to translate to.- Returns:
- the localized message.
- See Also:
io.github.mmm.nls
-
getDescriptor
NlsMessageDescriptor getDescriptor()
- Returns:
- the
NlsMessageDescriptor
.
-
-