Class TranslationContext
Represents the current context of the translation, i.e. what locale/language is being used, and the translated message strings we're interested in.
This allows objects to have more finer-grain control over their translation. Instead of having to
generate a MessageKey that someone else then uses to lookup the MessageSource
based on the current Locale, the object can use the TranslationContext to return the
translated string itself.
-
Constructor Summary
ConstructorsConstructorDescriptionTranslationContext(Locale locale, MessageSource messageSource) Creates a newTranslationContextinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanThe locale being used for the translationgetMessage(String code, Object... args) Allows this object to act a little like a MessageSource, which can help with statements().that().look().like().this();getMessage(String code, Object[] args, String defaultMessage) Same theory asgetMessage(String code, Object...args)but with a default messageThe MessageSource being used for translation (i.e.inthashCode()<T extends MessageFactory>
TnewFactory(Class<T> factoryInterface) toString()
-
Constructor Details
-
TranslationContext
Creates a new
TranslationContextinstance.- Parameters:
locale- The locale being used for the translationmessageSource- The MessageSource being used for translation (i.e. contains the message text indexed by code for a given resource bundle).
-
-
Method Details
-
newFactory
- Returns:
- a new
MessageFactoryinstance that returns translated messages against the given locale and message source
-
getMessage
Allows this object to act a little like a MessageSource, which can help with statements().that().look().like().this();
-
getMessage
Same theory as
getMessage(String code, Object...args)but with a default message -
getLocale
The locale being used for the translation
-
getMessageSource
The MessageSource being used for translation (i.e. contains the message text indexed by code for a given resource bundle).
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-