public class BundleUtil extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
BundleUtil.Event |
Modifier and Type | Field and Description |
---|---|
protected String |
pluginId |
protected static ResourceBundle |
productProps
The product properties used to override default localized text.
|
Constructor and Description |
---|
BundleUtil(String pluginId,
String bundleName,
ResourceBundle bundle)
Construct an instance of this class by specifying the plugin ID.
|
Modifier and Type | Method and Description |
---|---|
static BundleUtil |
getBundleUtil(Class<?> clazz)
Return the
BundleUtil for the class. |
String |
getString(String key)
Get the string identified by the given key and localized to the current locale.
|
String |
getString(String key,
List parameters)
Get the string identified by the given key and localized to the current locale, and replace placeholders in the localized
string with the string form of the parameters.
|
String |
getString(String key,
Object... parameters)
Get the string identified by the given key and localized to the current locale, and replace placeholders in the localized
string with the string form of the parameters.
|
String |
getStringOrKey(String key) |
String |
gs(BundleUtil.Event key,
Object... parameters) |
String |
gs(String key,
Object... parameters) |
boolean |
keyExists(String key)
Determines if the given key exists in the resource file.
|
protected static ResourceBundle productProps
protected final String pluginId
public BundleUtil(String pluginId, String bundleName, ResourceBundle bundle)
pluginId
- the identifier of the plugin for which this utility is being instantiatedbundleName
- the name of the resource bundle; used for problem reporting purposes onlybundle
- the resource bundlepublic static BundleUtil getBundleUtil(Class<?> clazz)
BundleUtil
for the class. The bundle must be in the same package or a parent package of the class.clazz
- public String getString(String key)
key
- the key in the resource file
"Missing message: " + key + " in: " + this.bundleName
if the string could
not be found in the current locale, or
"No message available"
if the key
is null.public boolean keyExists(String key)
key
- the key in the resource filepublic String getString(String key, List parameters)
key
- the key in the resource fileparameters
- the list of parameters that should replace placeholders in the localized string (e.g., "{0}", "{1}", etc.)
"Missing message: " + key + " in: " + this.bundleName
if the string could
not be found in the current locale, or
"No message available"
if the key
is null.public String getString(String key, Object... parameters)
key
- the key in the resource fileparameters
- the list of parameters that should replace placeholders in the localized string (e.g., "{0}", "{1}", etc.)
"Missing message: " + key + " in: " + this.bundleName
if the string could
not be found in the current locale, or
"No message available"
if the key
is null.public String gs(BundleUtil.Event key, Object... parameters)
Copyright © 2019. All rights reserved.