Class I18n


  • public class I18n
    extends java.lang.Object
    An utility class for internationalized message handling. Example usage::
     private static I18n i18n = I18n.getI18n("org.globus.resource");
     ...
     public void hello() {
        String filename = "file1";
        String msg = i18n.getMessage("noFile", new String[]{filename});
        ...
     }
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map mapping  
      private java.util.ResourceBundle messages  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected I18n​(java.util.ResourceBundle messages)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.ClassLoader getClassLoader()  
      static I18n getI18n​(java.lang.String resource)
      Retrieve a I18n instance by resource name.
      static I18n getI18n​(java.lang.String resource, java.lang.ClassLoader loader)
      Retrieve a I18n instance by resource name
      java.lang.String getMessage​(java.lang.String key)
      Gets a message from resource bundle.
      java.lang.String getMessage​(java.lang.String key, java.lang.Object arg)
      Gets a formatted message from resource bundle
      java.lang.String getMessage​(java.lang.String key, java.lang.Object[] vars)
      Gets a formatted message from resource bundle
      • Methods inherited from class java.lang.Object

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

      • mapping

        private static java.util.Map mapping
      • messages

        private java.util.ResourceBundle messages
    • Constructor Detail

      • I18n

        protected I18n​(java.util.ResourceBundle messages)
    • Method Detail

      • getI18n

        public static I18n getI18n​(java.lang.String resource)
        Retrieve a I18n instance by resource name.
        Parameters:
        resource - resource name. See ResourceBundle.getBundle()
      • getI18n

        public static I18n getI18n​(java.lang.String resource,
                                   java.lang.ClassLoader loader)
        Retrieve a I18n instance by resource name
        Parameters:
        resource - resource name. See ResourceBundle.getBundle()
        loader - the class loader to be used to load the resource. This parameter is only used initially to load the actual resource. Once the resource is loaded, this argument is ignored.
      • getClassLoader

        private static java.lang.ClassLoader getClassLoader()
      • getMessage

        public java.lang.String getMessage​(java.lang.String key)
                                    throws java.util.MissingResourceException
        Gets a message from resource bundle.
        Throws:
        java.util.MissingResourceException
      • getMessage

        public java.lang.String getMessage​(java.lang.String key,
                                           java.lang.Object arg)
                                    throws java.util.MissingResourceException
        Gets a formatted message from resource bundle
        Throws:
        java.util.MissingResourceException
      • getMessage

        public java.lang.String getMessage​(java.lang.String key,
                                           java.lang.Object[] vars)
                                    throws java.util.MissingResourceException
        Gets a formatted message from resource bundle
        Throws:
        java.util.MissingResourceException