Class LocalizedMessage

  • public class LocalizedMessage
    extends Object
    Represents a message that can be localised. The translations come from files. The underlying implementation uses java.text.MessageFormat.
    • Field Detail

      • sLocale

        private static Locale sLocale
        The locale to localise messages to.
      • bundle

        private final String bundle
        Name of the resource bundle to get messages from.
      • sourceClass

        private final Class<?> sourceClass
        Class of the source for this message.
      • key

        private final String key
        Key for the message format.
      • args

        private final Object[] args
        Arguments for java.text.MessageFormat, that is why type is Object[].

        Note: Changing types from Object[] will be huge breaking compatibility, as Module messages use some type formatting already, so better to keep it as Object[].

    • Constructor Detail

      • LocalizedMessage

        public LocalizedMessage​(String bundle,
                                Class<?> sourceClass,
                                String key,
                                Object... args)
        Creates a new LocalizedMessage instance.
        bundle - resource bundle name
        sourceClass - the Class that is the source of the message
        key - the key to locate the translation.
        args - arguments for the translation.
    • Method Detail

      • setLocale

        public static void setLocale​(Locale locale)
        Sets a locale to use for localization.
        locale - the locale to use for localization
      • getMessage

        public String getMessage()
        Gets the translated message.
        the translated message.
      • getBundle

        private ResourceBundle getBundle()
        Obtain the ResourceBundle. Uses the classloader of the class emitting this message, to be sure to get the correct bundle.
        a ResourceBundle.