|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
public class SimpleLocalizationServiceImpl
This class is the single point of access to all localization resources. It caches different ResourceBundles for different Locales.
Usage example:
SimpleLocalizationService ls = (SimpleLocalizationService) TurbineServices
.getInstance().getService(SimpleLocalizationService.SERVICE_NAME);
Then call getString(String, Locale, String)
, or one of
two methods to retrieve a ResourceBundle:
Field Summary |
---|
Fields inherited from interface org.apache.fulcrum.localization.SimpleLocalizationService |
---|
ROLE, SERVICE_NAME |
Constructor Summary | |
---|---|
SimpleLocalizationServiceImpl()
Creates a new instance. |
Method Summary | |
---|---|
void |
configure(org.apache.avalon.framework.configuration.Configuration conf)
Avalon lifecycle method |
String |
format(String bundleName,
Locale locale,
String key,
Object arg1)
Formats a localized value using the provided object. |
String |
format(String bundleName,
Locale locale,
String key,
Object[] args)
Looks up the value for key in the
ResourceBundle referenced by
bundleName , then formats that value for the
specified Locale using args . |
String |
format(String bundleName,
Locale locale,
String key,
Object arg1,
Object arg2)
Formats a localized value using the provided objects. |
ResourceBundle |
getBundle()
Convenience method to get the default ResourceBundle . |
ResourceBundle |
getBundle(String bundleName)
Returns a ResourceBundle given the bundle name and the default locale information supplied by the configuration. |
ResourceBundle |
getBundle(String bundleName,
Locale locale)
This method returns a ResourceBundle for the given bundle name and the given Locale. |
String[] |
getBundleNames()
Retrieves the list of names of bundles to search by default for ResourceBundle keys (as specified in the config
file). |
String |
getDefaultBundleName()
Retrieves the name of the default bundle (as specified in the config file), or the first in the list if there are more than one. |
String |
getDefaultCountry()
Retrieves the default country (specified in the config file). |
String |
getDefaultLanguage()
Retrieves the default language (specified in the config file). |
Locale |
getDefaultLocale()
Retrieves the default Locale (as created from default language and default country). |
String |
getString(String bundleName,
Locale locale,
String key)
Tries very hard to return a value, looking first in the specified bundle, then searching list of default bundles (giving precedence to earlier bundles over later bundles). |
protected String |
getStringOrNull(ResourceBundle rb,
String key)
Gets localized text from a bundle if it's there. |
protected void |
initBundleNames(String[] intBundleNames)
Initialize list of default bundle names. |
void |
initialize()
Called the first time the Service is used. |
void |
setBundle(String defaultBundle)
This method sets the name of the first bundle in the search list (the "default" bundle). |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled |
---|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleLocalizationServiceImpl()
Method Detail |
---|
public void configure(org.apache.avalon.framework.configuration.Configuration conf) throws org.apache.avalon.framework.configuration.ConfigurationException
configure
in interface org.apache.avalon.framework.configuration.Configurable
org.apache.avalon.framework.configuration.ConfigurationException
Configurable}
public void initialize() throws Exception
initialize
in interface org.apache.avalon.framework.activity.Initializable
Exception
protected void initBundleNames(String[] intBundleNames)
ignored
- names Ignored.public String getDefaultLanguage()
getDefaultLanguage
in interface SimpleLocalizationService
public String getDefaultCountry()
getDefaultCountry
in interface SimpleLocalizationService
public Locale getDefaultLocale()
getDefaultLocale
in interface SimpleLocalizationService
public String getDefaultBundleName()
SimpleLocalizationService
getDefaultBundleName
in interface SimpleLocalizationService
SimpleLocalizationService.getDefaultBundleName()
public String[] getBundleNames()
SimpleLocalizationService
ResourceBundle
keys (as specified in the config
file).
getBundleNames
in interface SimpleLocalizationService
SimpleLocalizationService.getBundleNames()
public ResourceBundle getBundle()
SimpleLocalizationService
ResourceBundle
.
getBundle
in interface SimpleLocalizationService
ResourceBundle
.SimpleLocalizationService.getBundle()
public ResourceBundle getBundle(String bundleName)
SimpleLocalizationService
getBundle
in interface SimpleLocalizationService
bundleName
- Name of bundle.
SimpleLocalizationService.getBundle(String)
public ResourceBundle getBundle(String bundleName, Locale locale)
getBundle
in interface SimpleLocalizationService
bundleName
- Name of bundle (or null
for the
default bundle).locale
- The locale (or null
for the locale
indicated by the default language and country).
public void setBundle(String defaultBundle)
setBundle
in interface SimpleLocalizationService
defaultBundle
- Name of default bundle.public String getString(String bundleName, Locale locale, String key) throws MissingResourceException
SimpleLocalizationService
getString
in interface SimpleLocalizationService
bundleName
- Name of the bundle to look in first.locale
- Locale to get text for.key
- Name of the text to retrieve.
MissingResourceException
- Specified key cannot be matched.SimpleLocalizationService.getString(String, Locale, String)
protected final String getStringOrNull(ResourceBundle rb, String key)
null
(ignoring a possible
MissingResourceException
).
public String format(String bundleName, Locale locale, String key, Object arg1)
SimpleLocalizationService
format
in interface SimpleLocalizationService
bundleName
- The bundle in which to look for the localizable text.locale
- The locale for which to format the text.key
- The identifier for the localized text to retrieve,arg1
- The object to use as {0} when formatting the localized text.
SimpleLocalizationService.format(String, Locale, String, Object)
public String format(String bundleName, Locale locale, String key, Object arg1, Object arg2)
SimpleLocalizationService
format
in interface SimpleLocalizationService
bundleName
- The bundle in which to look for the localizable text.locale
- The locale for which to format the text.key
- The identifier for the localized text to retrieve,arg1
- The object to use as {0} when formatting the localized text.arg2
- The object to use as {1} when formatting the localized text.
SimpleLocalizationService.format(String, Locale, String, Object, Object)
public String format(String bundleName, Locale locale, String key, Object[] args)
key
in the
ResourceBundle
referenced by
bundleName
, then formats that value for the
specified Locale
using args
.
format
in interface SimpleLocalizationService
bundleName
- The bundle in which to look for the localizable text.locale
- The locale for which to format the text.key
- The identifier for the localized text to retrieve,args
- The objects to use as {0}, {1}, etc. when
formatting the localized text.
key
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |