Class ResourceBundleManager
java.lang.Object
com.dlsc.gemsfx.util.ResourceBundleManager
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumTyped categories for the currently supported i18n bundle domains.static enumDeprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringformat(ResourceBundleManager.BundleType bundleType, String key, Object... args) Formats the localized string for the given bundle type and key withMessageFormat.static StringFormats the localized string for the given base name and key withMessageFormat.static ResourceBundlegetBundle(ResourceBundleManager.BundleType bundleType) Retrieves the resource bundle for the specified bundle type and the current application locale.static ResourceBundleDeprecated.usegetBundle(BundleType)instead.static ResourceBundleRetrieves the resource bundle for the specified base name and the current application locale.static LocaleReturns the current locale used to load resource bundles.static StringgetString(ResourceBundleManager.BundleType bundleType, String key) Retrieves a localized string from the resource bundle associated with a given bundle type.static StringgetString(ResourceBundleManager.BundleType bundleType, String key, String fallbackValue) Retrieves a localized string from the resource bundle associated with a given bundle type.static StringgetString(ResourceBundleManager.Type type, String key) Deprecated.usegetString(BundleType, String)instead.static StringgetString(ResourceBundleManager.Type type, String key, String fallbackValue) Deprecated.usegetString(BundleType, String, String)instead.static StringRetrieves a localized string from the resource bundle specified by the base name.static StringRetrieves a localized string from the resource bundle specified by the base name.static voidSets the current locale of the application.
-
Method Details
-
getBundle
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.
-
getBundle
Retrieves the resource bundle for the specified bundle type and the current application locale.- Parameters:
bundleType- the bundle type- Returns:
- the requested resource bundle
-
getBundle
Deprecated.usegetBundle(BundleType)instead.Retrieves the resource bundle for the specified deprecated type and the current application locale.- Parameters:
type- the deprecated bundle type- Returns:
- the requested resource bundle
-
setLocale
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.
-
getLocale
Returns the current locale used to load resource bundles.- Returns:
- the current locale
-
getString
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
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 provided fallback value.- Parameters:
baseName- the base name of the resource bundle.key- the key for the desired string in the bundle.fallbackValue- the fallback value used when the key or bundle is missing.- Returns:
- the localized string or fallback value.
-
getString
Retrieves a localized string from the resource bundle associated with a given bundle type.- Parameters:
bundleType- the type of the resource bundle.key- the key for the desired string in the bundle.- Returns:
- the localized string.
-
getString
public static String getString(ResourceBundleManager.BundleType bundleType, String key, String fallbackValue) Retrieves a localized string from the resource bundle associated with a given bundle type.- Parameters:
bundleType- the type of the resource bundle.key- the key for the desired string in the bundle.fallbackValue- the fallback value used when the key or bundle is missing.- Returns:
- the localized string or fallback value.
-
getString
Deprecated.usegetString(BundleType, String)instead.Retrieves a localized string from the resource bundle associated with a deprecated type.- Parameters:
type- the deprecated bundle typekey- the key for the desired string in the bundle- Returns:
- the localized string, or the key if it is missing
-
getString
@Deprecated public static String getString(ResourceBundleManager.Type type, String key, String fallbackValue) Deprecated.usegetString(BundleType, String, String)instead.Retrieves a localized string from the resource bundle associated with a deprecated type.- Parameters:
type- the deprecated bundle typekey- the key for the desired string in the bundlefallbackValue- the fallback value used when the key or bundle is missing- Returns:
- the localized string, or the fallback value if it is missing
-
format
public static String format(ResourceBundleManager.BundleType bundleType, String key, Object... args) Formats the localized string for the given bundle type and key withMessageFormat.- Parameters:
bundleType- the bundle typekey- the resource keyargs- the arguments inserted into the localized pattern- Returns:
- the formatted localized string
-
format
Formats the localized string for the given base name and key withMessageFormat.- Parameters:
baseName- the base name of the resource bundlekey- the resource keyargs- the arguments inserted into the localized pattern- Returns:
- the formatted localized string
-
ResourceBundleManager.BundleTypeinstead.