Class Localiser


  • public class Localiser
    extends java.lang.Object
    Localiser for messages in the DataNucleus system. Provides access to a singleton, via the
    getInstance
    method. Any plugin that provides its own resources via a properties file should call
    Localiser.registerBundle(...)
    before the resources are required to be used.

    The DataNucleus system is internationalisable hence messages (to log files or exceptions) can be displayed in multiple languages. Currently DataNucleus contains localisation files in the English and Spanish, but can be extended easily by adding localisation files in languages such as French, etc. The internationalisation operates around a Java ResourceBundle, loading a properties file. Messages are output via calling

    Localiser.msg("012345", args);
    The messages themselves are contained in a file for each package. For example, with the above example, we have "org.datanucleus.Localisation.properties". This contains entries such as
    012345=Initialising Schema "{0}" using "{1}" auto-start option
    So the 2 parameters specified in the
    Localiser.msg(...)
    call are inserted into the message.

    Extending for other languages

    The language-specific parts are always contained in the Localisation.properties file. To extend the current system to internationalise in, for example, French you would add a file "org.datanucleus.Localisation_fr.properties" and add entries with the required French text. If you want to extend this to another language and contribute the files for your language you need to find all files "Localisation.properties" and provide an alternative variant, raise an issue, and attach your patch to the issue.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean displayCodesInMessages
      Convenience flag whether to display numbers in messages.
      private static java.util.Locale locale  
      private static java.util.Map<java.lang.String,​java.text.MessageFormat> msgFormats  
      private static java.util.Map<java.lang.String,​java.lang.String> properties  
    • Constructor Summary

      Constructors 
      Constructor Description
      Localiser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String getMessage​(java.lang.String messageKey, java.lang.Object... msgArgs)
      Method to provide the MessageFormat logic.
      static java.lang.String msg​(java.lang.String messageKey)
      Message formatter for an internationalised message.
      static java.lang.String msg​(java.lang.String messageKey, long arg)
      Message formatter with one argument passed in that will be embedded in an internationalised message.
      static java.lang.String msg​(java.lang.String messageKey, java.lang.Object... args)
      Message formatter with arguments passed in that will be embedded in an internationalised message.
      static void registerBundle​(java.lang.String bundleName, java.lang.ClassLoader loader)
      Method to be called by plugins that have their own ResourceBundle, so the messages will be registered and available for use.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • locale

        private static java.util.Locale locale
      • displayCodesInMessages

        private static boolean displayCodesInMessages
        Convenience flag whether to display numbers in messages.
      • properties

        private static java.util.Map<java.lang.String,​java.lang.String> properties
      • msgFormats

        private static java.util.Map<java.lang.String,​java.text.MessageFormat> msgFormats
    • Constructor Detail

      • Localiser

        public Localiser()
    • Method Detail

      • registerBundle

        public static void registerBundle​(java.lang.String bundleName,
                                          java.lang.ClassLoader loader)
        Method to be called by plugins that have their own ResourceBundle, so the messages will be registered and available for use.
        Parameters:
        bundleName - Name of the bundle e.g "org.datanucleus.store.myplugin.Localisation"
        loader - Loader for the bundle
      • msg

        public static java.lang.String msg​(java.lang.String messageKey)
        Message formatter for an internationalised message.
        Parameters:
        messageKey - the message key
        Returns:
        the resolved message text
      • msg

        public static java.lang.String msg​(java.lang.String messageKey,
                                           long arg)
        Message formatter with one argument passed in that will be embedded in an internationalised message.
        Parameters:
        messageKey - the message key
        arg - the long argument
        Returns:
        the resolved message text
      • msg

        public static java.lang.String msg​(java.lang.String messageKey,
                                           java.lang.Object... args)
        Message formatter with arguments passed in that will be embedded in an internationalised message.
        Parameters:
        messageKey - the message key
        args - the arguments
        Returns:
        the resolved message text
      • getMessage

        private static final java.lang.String getMessage​(java.lang.String messageKey,
                                                         java.lang.Object... msgArgs)
        Method to provide the MessageFormat logic. All of the msg() methods are wrappers to this one.
        Parameters:
        messageKey - the message key
        msgArgs - an array of arguments to substitute into the message
        Returns:
        the resolved message text