public class GlobalMessageUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Locale |
FAILOVER_LOCALE
Used when the preferred locale (as defined by the user) is not available.
|
protected static LanguageChoice |
langChoice |
protected static ThreadLocal<Locale> |
threadLocales |
Constructor and Description |
---|
GlobalMessageUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
calculateString(String[] pkgNames,
String key,
Object[] parameters,
Class<?> resourceClass,
String bundleName)
Calls
calculateString(String[], String, Object[], Class, String, boolean) with the logNotFoundError parameter set to true to ensure proper error logging when the localized string cannot be
found. |
static String |
calculateString(String[] pkgNames,
String key,
Object[] parameters,
Class<?> resourceClass,
String bundleName,
boolean fallbackOnRoot) |
static String |
calculateString(String[] pkgNames,
String key,
Object[] parameters,
Class<?> resourceClass,
String bundleName,
boolean logNotFoundError,
boolean fallbackOnRoot)
Returns the localized string for the given
key and parameters in a bundle defined by the the
concatenation of the package names defined in packageName and @code bundleName} (the first valid
combination of packageName + bundleName wins), sing the provided resourceClass 's class
loader. |
static String |
formatErrorMessage(String key,
String msg) |
static LinkedHashSet<Locale> |
getActiveLocales()
Returns a
LinkedHashSet of Locale s for consideration when localizing text. |
static ResourceBundle |
getBundle(Locale locale,
String packagePath,
Class<?> resourceClass) |
static ResourceBundle |
getBundle(Locale locale,
String packagePath,
Class<?> resourceClass,
boolean fallbackOnRoot)
Returns a
ResourceBundle corresponding to the given Locale package and resource class. |
static ResourceBundle |
getBundle(String packagePath,
Class<?> resourceClass)
Retrieve a resource bundle of the default or fail-over locales.
|
static String |
getErrorString(ResourceBundle bundle,
String key) |
static String |
getErrorString(ResourceBundle bundle,
String key,
String param1) |
static String |
getErrorString(ResourceBundle bundle,
String key,
String param1,
String param2) |
static String |
getErrorString(ResourceBundle bundle,
String key,
String param1,
String param2,
String param3) |
static String |
getErrorString(ResourceBundle bundle,
String key,
String param1,
String param2,
String param3,
String param4) |
static Locale |
getLocale() |
protected static String |
getLocaleString(Locale locale)
Returns a string corresponding to the locale (Example: "en", "en_US").
|
static String |
getString(ResourceBundle bundle,
String key) |
static String |
getString(ResourceBundle bundle,
String key,
String param1) |
static String |
getString(ResourceBundle bundle,
String key,
String param1,
String param2) |
static String |
getString(ResourceBundle bundle,
String key,
String param1,
String param2,
String param3) |
static String |
getString(ResourceBundle bundle,
String key,
String param1,
String param2,
String param3,
String param4) |
static String |
getString(ResourceBundle bundle,
String key,
String param1,
String param2,
String param3,
String param4,
String param5) |
static String |
getString(ResourceBundle bundle,
String key,
String param1,
String param2,
String param3,
String param4,
String param5,
String param6) |
protected static boolean |
isMissingKey(String string)
Returns true if the given
string is null or is in the format of a missing key: !key!. |
static void |
setLocale(Locale newLocale) |
public static final Locale FAILOVER_LOCALE
protected static final LanguageChoice langChoice
protected static final ThreadLocal<Locale> threadLocales
public static String getString(ResourceBundle bundle, String key) throws MissingResourceException
MissingResourceException
public static String getErrorString(ResourceBundle bundle, String key)
public static String getString(ResourceBundle bundle, String key, String param1)
public static String getErrorString(ResourceBundle bundle, String key, String param1)
public static String getString(ResourceBundle bundle, String key, String param1, String param2)
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2)
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3)
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2, String param3)
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4)
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4, String param5)
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4, String param5, String param6)
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4)
public static void setLocale(Locale newLocale)
public static Locale getLocale()
public static LinkedHashSet<Locale> getActiveLocales()
LinkedHashSet
of Locale
s for consideration when localizing text. The
LinkedHashSet
contains the user selected preferred Locale
, the failover Locale
(Locale.ENGLISH
) and the Locale.ROOT
.LinkedHashSet
of Locale
s for consideration when translating textpublic static String calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName)
calculateString(String[], String, Object[], Class, String, boolean)
with the logNotFoundError
parameter set to true
to ensure proper error logging when the localized string cannot be
found.public static String calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName, boolean fallbackOnRoot)
public static String calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName, boolean logNotFoundError, boolean fallbackOnRoot)
key
and parameters
in a bundle defined by the the
concatenation of the package names defined in packageName
and @code bundleName} (the first valid
combination of packageName
+ bundleName
wins), sing the provided resourceClass
's class
loader.pkgNames
- an array of packages potentially containing the localized messages the first one found to
contain the messages is the one that is used to localize the messagekey
- the message key being looked upparameters
- parameters within the looked up messageresourceClass
- the class whose class loader is used to getch the resource bundlebundleName
- the name of the message bundlelogNotFoundError
- determines whether an error is logged when the localized string cannot be found - it can be
used to suppress the log in cases where it is known that various combinations of parameters
will be tried to fetch the message, to avoid unnecessary error logging.fallbackOnRoot
- if true, and a ResourceBundle
cannot be found for a given Locale
,
falls back on the ROOT Locale
key
and parameters
in a bundle defined by the the
concatenation of the package names defined in packageName
and @code bundleName} (the first valid
combination of packageName
+ @code bundleName} wins), sing the provided resourceClass
's class
loaderpublic static ResourceBundle getBundle(String packagePath, Class<?> resourceClass) throws MissingResourceException
packagePath
- The package to search inresourceClass
- the class to use to resolve the bundleMissingResourceException
- in case both resource bundles couldn't be found.public static ResourceBundle getBundle(Locale locale, String packagePath, Class<?> resourceClass)
public static ResourceBundle getBundle(Locale locale, String packagePath, Class<?> resourceClass, boolean fallbackOnRoot)
ResourceBundle
corresponding to the given Locale
package and resource class. Falls-back
on the ROOT Locale
, if the fallbackOnRoot
flag is true and the requested Locale is not available.locale
- the Locale
for which the ResourceBundle
is being requestedpackagePath
- resourceClass
- fallbackOnRoot
- if true, and a ResourceBundle
cannot be found for the requested Locale
, falls
back on the ROOT Locale
ResourceBundle
corresponding to the given Locale
package and resource classprotected static String getLocaleString(Locale locale)
locale
- The Locale
whose string representation it being returnedprotected static boolean isMissingKey(String string)
string
is null or is in the format of a missing key: !key!.string
- string
is null or is in the format of a missing key: !key!.Copyright © 2019 Hitachi Vantara. All rights reserved.