Class TranslationContext

java.lang.Object
nz.org.riskscape.engine.i18n.TranslationContext

public class TranslationContext extends Object

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 Details

  • Method Details

    • newFactory

      public <T extends MessageFactory> T newFactory(Class<T> factoryInterface)
      Returns:
      a new MessageFactory instance that returns translated messages against the given locale and message source
    • getMessage

      public String getMessage(String code, Object... args)

      Allows this object to act a little like a MessageSource, which can help with statements().that().look().like().this();

    • getLocale

      public Locale getLocale()

      The locale being used for the translation

    • getMessageSource

      public MessageSource getMessageSource()

      The MessageSource being used for translation (i.e. contains the message text indexed by code for a given resource bundle).

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object