Package org.pentaho.di.i18n
Class GlobalMessageUtil
java.lang.Object
org.pentaho.di.i18n.GlobalMessageUtil
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Locale
Used when the preferred locale (as defined by the user) is not available.protected static final LanguageChoice
protected static final ThreadLocal<Locale>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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>
Returns aLinkedHashSet
ofLocale
s for consideration when localizing text.static ResourceBundle
Retrieve a resource bundle of the default or fail-over locales.static ResourceBundle
static ResourceBundle
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
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
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
-
Field Details
-
FAILOVER_LOCALE
Used when the preferred locale (as defined by the user) is not available. -
langChoice
-
threadLocales
-
-
Constructor Details
-
GlobalMessageUtil
public GlobalMessageUtil()
-
-
Method Details
-
formatErrorMessage
-
getString
- Throws:
MissingResourceException
-
getErrorString
-
getString
-
getErrorString
-
getString
-
getErrorString
public static String getErrorString(ResourceBundle bundle, String key, String param1, String param2) -
getString
-
getErrorString
-
getString
-
getString
-
getString
-
getErrorString
-
setLocale
-
getLocale
-
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
-
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
-
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
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
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!.
-