Package org.pentaho.di.i18n
Class GlobalMessageUtil
- java.lang.Object
-
- org.pentaho.di.i18n.GlobalMessageUtil
-
public class GlobalMessageUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description GlobalMessageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName)
CallscalculateString(String[], String, Object[], Class, String, boolean)
with thelogNotFoundError
parameter set totrue
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 givenkey
andparameters
in a bundle defined by the the concatenation of the package names defined inpackageName
and @code bundleName} (the first valid combination ofpackageName
+bundleName
wins), sing the providedresourceClass
's class loader.static String
formatErrorMessage(String key, String msg)
static LinkedHashSet<Locale>
getActiveLocales()
Returns aLinkedHashSet
ofLocale
s for consideration when localizing text.static ResourceBundle
getBundle(String packagePath, Class<?> resourceClass)
Retrieve a resource bundle of the default or fail-over locales.static ResourceBundle
getBundle(Locale locale, String packagePath, Class<?> resourceClass)
static ResourceBundle
getBundle(Locale locale, String packagePath, Class<?> resourceClass, boolean fallbackOnRoot)
Returns aResourceBundle
corresponding to the givenLocale
package and resource class.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 givenstring
is null or is in the format of a missing key: !key!.static void
setLocale(Locale newLocale)
-
-
-
Field Detail
-
FAILOVER_LOCALE
public static final Locale FAILOVER_LOCALE
Used when the preferred locale (as defined by the user) is not available.
-
langChoice
protected static final LanguageChoice langChoice
-
threadLocales
protected static final ThreadLocal<Locale> threadLocales
-
-
Method Detail
-
getString
public static String getString(ResourceBundle bundle, String key) throws MissingResourceException
- Throws:
MissingResourceException
-
getErrorString
public static String getErrorString(ResourceBundle bundle, String key)
-
getString
public static String getString(ResourceBundle bundle, String key, String param1)
-
getErrorString
public static String getErrorString(ResourceBundle bundle, String key, String param1)
-
getString
public static String getString(ResourceBundle bundle, String key, String param1, String param2)
-
getErrorString
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2)
-
getString
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3)
-
getErrorString
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2, String param3)
-
getString
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4)
-
getString
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4, String param5)
-
getString
public static String getString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4, String param5, String param6)
-
getErrorString
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4)
-
setLocale
public static void setLocale(Locale newLocale)
-
getLocale
public static Locale getLocale()
-
getActiveLocales
public static LinkedHashSet<Locale> getActiveLocales()
Returns aLinkedHashSet
ofLocale
s for consideration when localizing text. TheLinkedHashSet
contains the user selected preferredLocale
, the failoverLocale
(Locale.ENGLISH
) and theLocale.ROOT
.- Returns:
- Returns a
LinkedHashSet
ofLocale
s for consideration when translating text
-
calculateString
public static String calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName)
CallscalculateString(String[], String, Object[], Class, String, boolean)
with thelogNotFoundError
parameter set totrue
to ensure proper error logging when the localized string cannot be found.
-
calculateString
public static String calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName, boolean fallbackOnRoot)
-
calculateString
public static String calculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName, boolean logNotFoundError, boolean fallbackOnRoot)
Returns the localized string for the givenkey
andparameters
in a bundle defined by the the concatenation of the package names defined inpackageName
and @code bundleName} (the first valid combination ofpackageName
+bundleName
wins), sing the providedresourceClass
's class loader.- Parameters:
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 aResourceBundle
cannot be found for a givenLocale
, falls back on the ROOTLocale
- Returns:
- the localized string for the given
key
andparameters
in a bundle defined by the the concatenation of the package names defined inpackageName
and @code bundleName} (the first valid combination ofpackageName
+ @code bundleName} wins), sing the providedresourceClass
's class loader
-
getBundle
public static ResourceBundle getBundle(String packagePath, Class<?> resourceClass) throws MissingResourceException
Retrieve a resource bundle of the default or fail-over locales.- Parameters:
packagePath
- The package to search inresourceClass
- the class to use to resolve the bundle- Returns:
- The resource bundle
- Throws:
MissingResourceException
- in case both resource bundles couldn't be found.
-
getBundle
public static ResourceBundle getBundle(Locale locale, String packagePath, Class<?> resourceClass)
-
getBundle
public static ResourceBundle getBundle(Locale locale, String packagePath, Class<?> resourceClass, boolean fallbackOnRoot)
Returns aResourceBundle
corresponding to the givenLocale
package and resource class. Falls-back on the ROOTLocale
, if thefallbackOnRoot
flag is true and the requested Locale is not available.- Parameters:
locale
- theLocale
for which theResourceBundle
is being requestedpackagePath
-resourceClass
-fallbackOnRoot
- if true, and aResourceBundle
cannot be found for the requestedLocale
, falls back on the ROOTLocale
- Returns:
- a
ResourceBundle
corresponding to the givenLocale
package and resource class
-
getLocaleString
protected static String getLocaleString(Locale locale)
Returns a string corresponding to the locale (Example: "en", "en_US").- Parameters:
locale
- TheLocale
whose string representation it being returned- Returns:
- a string corresponding to the locale (Example: "en", "en_US").
-
isMissingKey
protected static boolean isMissingKey(String string)
Returns true if the givenstring
is null or is in the format of a missing key: !key!.- Parameters:
string
-- Returns:
- true if the given
string
is null or is in the format of a missing key: !key!.
-
-