-
- All Superinterfaces:
Localizable,LocalizableObject
public interface NlsMessage extends Localizable
This is the interface for an internationalized message. It stores aninternationalized-messageseparated from language independentarguments. This approach ensures that the message is always available in the internationalized language (should be English) while it still allows totranslatethe message to a native language. For an introduction first readhere
The format of theinternationalized-messageis similar toMessageFormat. This allows to migrate existing code fromMessageFormattoNlsMessageeasily. However, there are some advanced features available. While using numbers to identify theargumentsis 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. SeeNlsVariablefor the specification of the argument syntax.
To specifyNlsMessages you create anNlsBundleper 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 StringLOCALIZATION_FAILURE_PREFIXThe prefix appended to themessageif the localization (translation) failed.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ObjectgetArgument(String key)This method gets the language independent argument value for the givenkey.NlsArgumentsgetArguments()NlsMessageDescriptorgetDescriptor()StringgetInternationalizedMessage()This method gets the internationalized message what is the actual message template for theroot localewithout resolving itsarguments.default StringgetLocalizedMessage(Locale locale)This method gets the resolved and localized message.
First it will translate theinternationalized messageto 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 themessageif 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 localewithout 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:LocalizableThis method gets the language independent argument value for the givenkey.- Specified by:
getArgumentin interfaceLocalizable- Parameters:
key- is the name of the requested argument.- Returns:
- the argument value for the given key or
nullif NOT defined. - See Also:
NlsArguments.get(String),NlsVariable
-
getArguments
NlsArguments getArguments()
- Returns:
- the dynamic
NlsArgumentsto 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 messageto the givenLocale. If this fails for whatever reason, theinternationalized messageis used as fallback.
Then this message gets resolved by replacing thevariableswith their accordingarguments.
Example:
We assume theinternationalized messageis"Welcome {name}!"and theargumentwith thekey"name"has thevalue"Joelle". After translation toLocale.GERMANthe 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 localeis used as fallback resulting in"Welcome Joelle!".- Specified by:
getLocalizedMessagein 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.
-
-