Class ResourceBundleManager

java.lang.Object
com.dlsc.gemsfx.util.ResourceBundleManager

public class ResourceBundleManager extends Object
This class provides a centralized mechanism to retrieve localized strings from property files based on the current locale settings. It caches the resource bundles to avoid repetitive and unnecessary loading of the properties files.

Usage involves retrieving strings via base names of the resource bundles or by using predefined types which represent specific views or components in the application.

  • Method Details

    • getBundle

      public static ResourceBundle getBundle(String baseName)
      Retrieves the resource bundle for the specified base name and the current application locale. This method will return a cached bundle if it exists, or load a new bundle if it does not.
      Parameters:
      baseName - the base name of the resource bundle.
      Returns:
      the requested resource bundle.
    • setLocale

      public static void setLocale(Locale locale)
      Sets the current locale of the application. If the locale is changed, the method clears the cache of loaded resource bundles.
      Parameters:
      locale - the new locale to set as the current.
    • getString

      public static String getString(String baseName, String key)
      Retrieves a localized string from the resource bundle specified by the base name. If the key is not found, it logs a warning and returns the key itself.
      Parameters:
      baseName - the base name of the resource bundle.
      key - the key for the desired string in the bundle.
      Returns:
      the localized string.
    • getString

      public static String getString(ResourceBundleManager.Type type, String key)
      Retrieves a localized string from the resource bundle associated with a given type.
      Parameters:
      type - the type of the resource bundle.
      key - the key for the desired string in the bundle.
      Returns:
      the localized string.