Class I18n


  • public class I18n
    extends Object
    The I18n class provides methods for applications and services to internationalize their messages.

    In order for I18n to internationalize messages, it needs to determine the resource bundle name, i.e., properties file name. I18n supports two techniques by which applications and services can specify their I18N resource bundle name. The recommendation is to specify them during service (or application) registration via SMS using a XML file (see com.iplanet.services.ServiceManager and service registration DTD). The XML file could specify the resource bundle name (the attribute defined in the DTD is i18nFileName) and optionally URL of the jar file which contains the property file (the attribute defined in the DTD is resourceBundleURL). If URL for the jar file is not specified it is assumed that the resource bundle is in the CLASSPATH. Using this technique it is possible to customize resource bundle name and URL of the jar file by using SMS APIs, commands (CLI) or GUI. The solution makes internationalization of messages very dynamic and highly customizable.

    I18n class be instantiated by calling the static getInstance(String serviceName) method. The parameter serviceName specifies the name of the service as mentioned in the XML file at the time of service registration.

    Alternatively services and application can instantiate I18n object by specifying the resource bundle name (i.e., properties file name). Using this technique it is not possible to customize at runtime either the resource bundle name or the URL of the jar file that contains the properties file name. It is assumed that the properties file is present in CLASSPATH

    • Constructor Detail

      • I18n

        protected I18n​(String serviceName)
        This constructor takes the name of the component as an argument and it should match with name of the resource bundle
    • Method Detail

      • getInstance

        public static I18n getInstance​(String serviceName)
        Method to get an instance of I18n object that has been either previously created or to obtain a new instance if it does'nt exist
        Parameters:
        serviceName - name of the service for which messages must be internationalized
        Returns:
        I18n object
      • getLocale

        public static Locale getLocale​(String stringformat)
        Method to obtain Locale object given its string representation
        Parameters:
        stringformat - Locale in a string format
        Returns:
        Locale object
      • getResBundleName

        public String getResBundleName()
        Returns the resource file name associated with the service
        Returns:
        Returns the the ResourceBundle name associated with the service
      • getString

        public String getString​(String key,
                                String locale)
        Method to obtain internationalized message from the resource bundle given the key and locale.
        Parameters:
        key - key string in the properties file
        locale - locale in a string format
        Returns:
        returns internationalized message for the specified key
      • getString

        public String getString​(String key)
        Method to obtain internationalized message from the resource bundle given the key.
        Parameters:
        key - Key string in the properties file
        Returns:
        Returns value to the specified key
      • getString

        public String getString​(String key,
                                String locale,
                                Object[] params)
        Method to obtain internationalized message from the resource bundle given the key, locale and parameters.
        Parameters:
        key - key string in the properties file
        locale - locale in a string format
        params - parameters to be applied to the message
        Returns:
        returns internationalized message for the specified key
      • getString

        public String getString​(String key,
                                Object[] params)
        Method to obtain internationalized message from the resource bundle given the key and parameters.
        Parameters:
        key - Key string in the properties file
        params - parameters to be applied to the message
        Returns:
        Returns value to the specified key
      • decodeCharset

        public static String decodeCharset​(String s,
                                           String charset)
        Decodes the string into specified charset
        Parameters:
        s - string to be decoded
        charset - character set in which the string to be decoded
        Returns:
        Returns the decoded string
      • isAscii

        public static boolean isAscii​(String s)
        Checks whether the string is ascii or not
        Parameters:
        s - string to be checked
        Returns:
        true if the string is ascii, otherwise false
      • format

        public static String format​(String pattern,
                                    Long j,
                                    String l)
        Formats the objects into specified message format.
        Parameters:
        pattern - pattern for which the message to be formatted
        j - Object to be formatted & substituted
        l - locale in a string format
        Returns:
        Returns the formatted message
      • format

        public static String format​(String pattern,
                                    Integer i,
                                    String l)
        Formats the objects into specified message format.
        Parameters:
        pattern - pattern for which the message to be formatted
        i - Integer to be formatted & substituted
        l - locale in a string format
        Returns:
        Returns the formatted message
      • format

        public static String format​(String pattern,
                                    Date d,
                                    TimeZone tz,
                                    String l)
        Formats the objects into specified message format
        Parameters:
        pattern - pattern for which the message to be formatted
        d - date
        tz - Timezone
        l - locale in a string format
        Returns:
        Returns the formatted message