Module org.jcommon

Class LangResourceBundle

    • Constructor Detail

      • LangResourceBundle

        public LangResourceBundle()
    • Method Detail

      • setLocale

        public static void setLocale​(Locale locale)
        Set the locale of the lang resource. When a locale is set, all lang resource file associated to the locale are loaded from the resource path.
        Parameters:
        locale - the new locale.
      • setResourcePath

        public static void setResourcePath​(String path)
        Set the root path of the resource language files.
        Parameters:
        path - the path of the resource language files root.
      • getResourcePath

        public static String getResourcePath()
        Set the root path of the resource language files.
        Returns:
        the path of the resource language files root.
      • getResources

        public static HashMap<String,​String> getResources()
        Get the map containing the lang resources.
        Returns:
        a hash map containing the lang resource.
      • getAvailableLocales

        public static ArrayList<String> getAvailableLocales()
        Get the available locales.
        Returns:
        a list of available locales.
      • getResource

        public static Object getResource​(String key,
                                         String param)
        Get a resource associated to a key. If the key does not correspond to any resource, the key itself is returned. The parameter given is applied to the resource if it accept parameter.
        Parameters:
        key - the key inditifying the resource to return
        param - the parameter to apply to the resource.
        Returns:
        the resource or the key if no resource is available.
      • getResource

        public static Object getResource​(String key,
                                         String[] params)
        Get a parametrized resource associated to a key. If the key does not correspond to any resource, the key itself is returned. Parameters enable to caraterize the resource. Parameter are identified in a resource by a % followed by the parameter number. For example, if the resource is "Hello %1 and %2.", and parameters are "Fox" and "Dana", the object returned is "Hello Fox and Dana."
        Parameters:
        key - the key inditifying the resource to return
        params - the parameters of the resource.
        Returns:
        the resource parametrized or the key if no resource is available.
      • getStringS

        public static String getStringS​(String key)
        Get a resource into a String form. This method is simply a call of getResource(key).toString();.
        Parameters:
        key - the key inditifying the resource to return
        Returns:
        the resource or the key if no resource is available.
      • getStringCap

        public static String getStringCap​(String key)
        Get a resource into a String form. This method call the getString(key) and put in upper case the fisrt character of the string.
        Parameters:
        key - the key identifying the resource.
        Returns:
        the resource or the key if no resource is available.
      • getString

        public static String getString​(String key,
                                       String[] aParams)
        Get a parametric resource into a String form. This method is simply a call of getResource(key, aParams).toString(); on the current bundle.
        Parameters:
        key - the key referencing the resource.
        aParams - the parameters to use as replacements in the resource (if any).
        Returns:
        the localized string with integrated parameters.