Package org.apache.fulcrum.localization
Class DefaultLocalizationService
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
org.apache.fulcrum.localization.DefaultLocalizationService
- All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable,org.apache.avalon.framework.configuration.Configurable,org.apache.avalon.framework.logger.LogEnabled,LocalizationService,SimpleLocalizationService
public class DefaultLocalizationService
extends SimpleLocalizationServiceImpl
implements LocalizationService
This class is the single point of access to all localization resources. It caches different ResourceBundles for different Locales.
Usage example:
LocalizationService ls = (LocalizationService) TurbineServices
.getInstance().getService(LocalizationService.SERVICE_NAME);
Then call SimpleLocalizationServiceImpl.getString(String, Locale, String), or one of
four methods to retrieve a ResourceBundle:
- getBundle("MyBundleName")
- getBundle("MyBundleName", httpAcceptLanguageHeader)
- etBundle("MyBundleName", HttpServletRequest)
- getBundle("MyBundleName", Locale)
- etc.
- Version:
- $Id$ avalon.component name="localization" lifestyle="singleton" avalon.service type="org.apache.fulcrum.localization.LocalizationService"
- Author:
- Jonas Maurus, Jon S. Stevens, Frank Y. Kim, Daniel Rall, Leonard Richardson, Stephen McConnell, Thomas Vandahl
-
Field Summary
Fields inherited from interface org.apache.fulcrum.localization.LocalizationService
ACCEPT_LANGUAGE, ROLE, SERVICE_NAMEFields inherited from interface org.apache.fulcrum.localization.SimpleLocalizationService
ROLE, SERVICE_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBundle(jakarta.servlet.http.HttpServletRequest req) This method returns a ResourceBundle given the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest.Convenience method to get aResourceBundlebased on name and HTTPAccept-Languageheader from aHttpServletRequest.This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.getLocale(jakarta.servlet.http.HttpServletRequest req) Attempts to pull theAccept-Languageheader out of theHttpServletRequestobject and then parse it.Parses theAccept-Languageheader and attempts to create aLocalefrom it.Methods inherited from class org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
configure, format, format, format, getBundle, getBundle, getBundle, getBundleNames, getDefaultBundleName, getDefaultCountry, getDefaultLanguage, getDefaultLocale, getString, getString, getStringOrNull, initBundleNames, initialize, setBundleMethods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLoggerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.fulcrum.localization.SimpleLocalizationService
format, format, format, getBundle, getBundle, getBundle, getBundleNames, getDefaultBundleName, getDefaultCountry, getDefaultLanguage, getDefaultLocale, getString, getString, setBundle
-
Constructor Details
-
DefaultLocalizationService
public DefaultLocalizationService()Creates a new instance.
-
-
Method Details
-
getBundle
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.- Specified by:
getBundlein interfaceLocalizationService- Parameters:
bundleName- Name of bundle.languageHeader- A String with the language header.- Returns:
- A localized ResourceBundle.
- See Also:
-
getBundle
This method returns a ResourceBundle given the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest.- Specified by:
getBundlein interfaceLocalizationService- Parameters:
req- HttpServletRequest.- Returns:
- A localized ResourceBundle.
-
getBundle
Description copied from interface:LocalizationServiceConvenience method to get aResourceBundlebased on name and HTTPAccept-Languageheader from aHttpServletRequest.- Specified by:
getBundlein interfaceLocalizationService- Parameters:
bundleName- Name of the bundle to use if the request's locale cannot be resolved.req- HttpServletRequest.- Returns:
- A localized ResourceBundle.
- See Also:
-
getLocale
Description copied from interface:LocalizationServiceAttempts to pull theAccept-Languageheader out of theHttpServletRequestobject and then parse it. If the header is not present, it will return anullLocale.- Specified by:
getLocalein interfaceLocalizationService- Parameters:
req- The HTTP request to parse theAccept-Languageof.- Returns:
- The parsed locale.
-
getLocale
Description copied from interface:LocalizationServiceParses theAccept-Languageheader and attempts to create aLocalefrom it.- Specified by:
getLocalein interfaceLocalizationService- Parameters:
header- The language header (i.e.en, es;q=0.8, zh-TW;q=0.1), ornullfor the locale corresponding to the default language and country.- Returns:
- The parsed locale, or a locale corresponding to the language and country defaults.
-