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 LocaleFAILOVER_LOCALEUsed when the preferred locale (as defined by the user) is not available.protected static LanguageChoicelangChoiceprotected static ThreadLocal<Locale>threadLocales
-
Constructor Summary
Constructors Constructor Description GlobalMessageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcalculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName)CallscalculateString(String[], String, Object[], Class, String, boolean)with thelogNotFoundErrorparameter set totrueto ensure proper error logging when the localized string cannot be found.static StringcalculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName, boolean fallbackOnRoot)static StringcalculateString(String[] pkgNames, String key, Object[] parameters, Class<?> resourceClass, String bundleName, boolean logNotFoundError, boolean fallbackOnRoot)Returns the localized string for the givenkeyandparametersin a bundle defined by the the concatenation of the package names defined inpackageNameand @code bundleName} (the first valid combination ofpackageName+bundleNamewins), sing the providedresourceClass's class loader.static StringformatErrorMessage(String key, String msg)static LinkedHashSet<Locale>getActiveLocales()Returns aLinkedHashSetofLocales for consideration when localizing text.static ResourceBundlegetBundle(String packagePath, Class<?> resourceClass)Retrieve a resource bundle of the default or fail-over locales.static ResourceBundlegetBundle(Locale locale, String packagePath, Class<?> resourceClass)static ResourceBundlegetBundle(Locale locale, String packagePath, Class<?> resourceClass, boolean fallbackOnRoot)Returns aResourceBundlecorresponding to the givenLocalepackage and resource class.static StringgetErrorString(ResourceBundle bundle, String key)static StringgetErrorString(ResourceBundle bundle, String key, String param1)static StringgetErrorString(ResourceBundle bundle, String key, String param1, String param2)static StringgetErrorString(ResourceBundle bundle, String key, String param1, String param2, String param3)static StringgetErrorString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4)static LocalegetLocale()protected static StringgetLocaleString(Locale locale)Returns a string corresponding to the locale (Example: "en", "en_US").static StringgetString(ResourceBundle bundle, String key)static StringgetString(ResourceBundle bundle, String key, String param1)static StringgetString(ResourceBundle bundle, String key, String param1, String param2)static StringgetString(ResourceBundle bundle, String key, String param1, String param2, String param3)static StringgetString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4)static StringgetString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4, String param5)static StringgetString(ResourceBundle bundle, String key, String param1, String param2, String param3, String param4, String param5, String param6)protected static booleanisMissingKey(String string)Returns true if the givenstringis null or is in the format of a missing key: !key!.static voidsetLocale(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 aLinkedHashSetofLocales for consideration when localizing text. TheLinkedHashSetcontains the user selected preferredLocale, the failoverLocale(Locale.ENGLISH) and theLocale.ROOT.- Returns:
- Returns a
LinkedHashSetofLocales 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 thelogNotFoundErrorparameter set totrueto 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 givenkeyandparametersin a bundle defined by the the concatenation of the package names defined inpackageNameand @code bundleName} (the first valid combination ofpackageName+bundleNamewins), 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 aResourceBundlecannot be found for a givenLocale, falls back on the ROOTLocale- Returns:
- the localized string for the given
keyandparametersin a bundle defined by the the concatenation of the package names defined inpackageNameand @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 aResourceBundlecorresponding to the givenLocalepackage and resource class. Falls-back on the ROOTLocale, if thefallbackOnRootflag is true and the requested Locale is not available.- Parameters:
locale- theLocalefor which theResourceBundleis being requestedpackagePath-resourceClass-fallbackOnRoot- if true, and aResourceBundlecannot be found for the requestedLocale, falls back on the ROOTLocale- Returns:
- a
ResourceBundlecorresponding to the givenLocalepackage and resource class
-
getLocaleString
protected static String getLocaleString(Locale locale)
Returns a string corresponding to the locale (Example: "en", "en_US").- Parameters:
locale- TheLocalewhose 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 givenstringis null or is in the format of a missing key: !key!.- Parameters:
string-- Returns:
- true if the given
stringis null or is in the format of a missing key: !key!.
-
-