Class LocaleProvider
java.lang.Object
net.simplace.core.service.LocaleProvider
Singleton resource manager for localized strings, read from resource bundles on the class path (e.g.
LocaleBundle). Optionally, bundles prefixed with DEV_ are looked up in an additional
directory first (see setInterceptPath(URL)).- Author:
- Andreas Enders
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic LocaleProviderReturns the singleton instance of LocaleProvider.static LocaleProvidergetInstance(Locale aLocale) Returns the singleton instance of LocaleProvider after setting its current locale.Returns the locale currently in use.Returns a localized string fromLocaleBundleusing the current locale.Returns a localized string using the current locale.Returns a localized string using the current locale, with a default value for missing keys.Returns a localized string from the given bundle using the specified locale.Returns a localized string from the given bundle using the specified locale, with a default value for missing keys.voidResets the locale of this provider to the default locale of the JVM.voidsetDefaultLanguage(String aLocalization) Sets the default locale of the JVM to the given language and resets this provider to the new default locale.voidsetInterceptPath(URL tInterceptPath) Sets a directory in which bundles prefixed withDEV_are looked up before the class path.voidSets the locale used by this provider.
-
Field Details
-
DEFAULT_EMPTY
Value returned if no localized string was found and no default value was given.- See Also:
-
CUSTOMER_PREFIX
Prefix for customer specific resource bundles, e.g.CustomerLocaleBundle.- See Also:
-
-
Method Details
-
getInstance
Returns the singleton instance of LocaleProvider.- Returns:
- the singleton instance of LocaleProvider
-
getInstance
Returns the singleton instance of LocaleProvider after setting its current locale.- Parameters:
aLocale- locale to use from now on- Returns:
- the singleton instance of LocaleProvider
-
getString
Returns a localized string using the current locale. If the key is not found in the given bundle, it is looked up inLocaleBundle; if the key contains spaces, it is also tried with spaces replaced by underscores. In development mode the key itself is returned if nothing was found.- Parameters:
aStringSet- name of the resource bundleaKey- key of the string- Returns:
- the localized string, or
DEFAULT_EMPTYif not found
-
getString
Returns a localized string fromLocaleBundleusing the current locale.- Parameters:
aKey- key of the string- Returns:
- the localized string, or
DEFAULT_EMPTYif not found
-
getString
Returns a localized string using the current locale, with a default value for missing keys. If the key is not found in the given bundle, it is looked up inLocaleBundle; if the key contains spaces, it is also tried with spaces replaced by underscores.- Parameters:
aStringSet- name of the resource bundleaKey- key of the stringaDefaultValue- value to return if the key is not found- Returns:
- the localized string, or aDefaultValue if not found
-
getString
Returns a localized string from the given bundle using the specified locale. No fallback bundle is used.- Parameters:
aStringSet- name of the resource bundleaKey- key of the stringaLocale- locale to use- Returns:
- the localized string, or
DEFAULT_EMPTYif not found
-
getString
Returns a localized string from the given bundle using the specified locale, with a default value for missing keys. No fallback bundle is used.- Parameters:
aStringSet- name of the resource bundleaKey- key of the stringaLocale- locale to useaDefaultValue- value to return if the key is not found; ifnull,DEFAULT_EMPTYis returned instead- Returns:
- the localized string, or the default value if not found
-
getLocale
Returns the locale currently in use.- Returns:
- a copy of the current locale
-
setLocale
Sets the locale used by this provider.- Parameters:
aLocale- locale to use
-
setInterceptPath
Sets a directory in which bundles prefixed withDEV_are looked up before the class path.- Parameters:
tInterceptPath- URL of the directory, ornullto use the class path only
-
resetLocale
public void resetLocale()Resets the locale of this provider to the default locale of the JVM. -
getLocaleKey
- Returns:
- the language code of the current locale, e.g.
de
-
setDefaultLanguage
Sets the default locale of the JVM to the given language and resets this provider to the new default locale. A graphical client has to reinitialise its look and feel afterwards.- Parameters:
aLocalization- locale string; only the first two characters (language code) are used, e.g.de_DE
-