Class LocalizationTool
- java.lang.Object
-
- org.apache.turbine.services.localization.LocalizationTool
-
- All Implemented Interfaces:
ApplicationTool
public class LocalizationTool extends Object implements ApplicationTool
A pull tool which provides lookups for localized text by delegating to the configured FulcrumLocalizationService.- Author:
- Eric Pugh, Daniel Rall, Jon Stevens
-
-
Constructor Summary
Constructors Constructor Description LocalizationTool()Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringformat(String key, Object... args)Formats a localized value using the provided objects.Stringget(String key)Performs text lookups for localization.protected StringgetBundleName(Object data)The return value of this method is used to set the name of the bundle used by this tool.LocalegetLocale()Gets the current locale.voidinit(Object data)Sets the request to get theAccept-Languageheader from (reset on each request).voidrefresh()No-op.
-
-
-
Constructor Detail
-
LocalizationTool
public LocalizationTool()
Creates a new instance. Used byPullService.
-
-
Method Detail
-
get
public String get(String key)
Performs text lookups for localization.
Assuming there is a instance of this class with a HTTP request set in your template's context named
l10n, the VTL$l10n.HELLOwould render tohellofor English requests andholain Spanish (depending on the value of the HTTP request'sAccept-Languageheader).- Parameters:
key- The identifier for the localized text to retrieve.- Returns:
- The localized text.
-
getBundleName
protected String getBundleName(Object data)
The return value of this method is used to set the name of the bundle used by this tool. Useful as a hook for using a different bundle than specified in yourLocalizationServiceconfiguration.- Parameters:
data- The inputs passed frominit(Object). (ignored by this implementation).- Returns:
- the name of the bundle to use
-
format
public String format(String key, Object... args)
Formats a localized value using the provided objects.- Parameters:
key- The identifier for the localized text to retrieve,args- The objects to use as {0}, {1}, etc. when formatting the localized text.- Returns:
- Formatted localized text.
-
init
public void init(Object data)
Sets the request to get theAccept-Languageheader from (reset on each request).- Specified by:
initin interfaceApplicationTool- Parameters:
data- initialization data
-
refresh
public void refresh()
No-op.- Specified by:
refreshin interfaceApplicationTool
-
-