org.apache.turbine.services.localization
Class LocalizationTool

java.lang.Object
  extended byorg.apache.turbine.services.localization.LocalizationTool
All Implemented Interfaces:
ApplicationTool

public class LocalizationTool
extends java.lang.Object
implements ApplicationTool

A pull tool which provides lookups for localized text by delegating to the configured LocalizationService.

Version:
$Id: LocalizationTool.java 551164 2007-06-27 14:04:14Z seade $
Author:
Daniel Rall, Jon Stevens

Field Summary
protected  java.lang.String bundleName
          The name of the bundle for this tool to use.
protected  java.util.Locale locale
          The language and country information parsed from the request's Accept-Language header.
 
Constructor Summary
LocalizationTool()
          Creates a new instance.
 
Method Summary
 java.lang.String format(java.lang.String key, java.util.List args)
          Formats a localized value using the provided objects.
 java.lang.String format(java.lang.String key, java.lang.Object arg1)
          Formats a localized value using the provided object.
 java.lang.String format(java.lang.String key, java.lang.Object[] args)
          Formats a localized value using the provided objects.
 java.lang.String format(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
          Formats a localized value using the provided objects.
 java.lang.String get(java.lang.String key)
          Performs text lookups for localization.
protected  java.lang.String getBundleName(java.lang.Object data)
          The return value of this method is used to set the name of the bundle used by this tool.
 java.util.Locale getLocale()
          Gets the current locale.
 void init(java.lang.Object data)
          Sets the request to get the Accept-Language header from (reset on each request).
 void refresh()
          No-op.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locale

protected java.util.Locale locale
The language and country information parsed from the request's Accept-Language header. Reset on each request.


bundleName

protected java.lang.String bundleName
The name of the bundle for this tool to use.

Constructor Detail

LocalizationTool

public LocalizationTool()
Creates a new instance. Used by PullService.

Method Detail

get

public java.lang.String get(java.lang.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.HELLO would render to hello for English requests and hola in Spanish (depending on the value of the HTTP request's Accept-Language header).

Parameters:
key - The identifier for the localized text to retrieve.
Returns:
The localized text.

getLocale

public java.util.Locale getLocale()
Gets the current locale.

Returns:
The locale currently in use.

getBundleName

protected java.lang.String getBundleName(java.lang.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 specifed in your LocalizationService configuration.

Parameters:
data - The inputs passed from init(Object). (ignored by this implementation).

format

public java.lang.String format(java.lang.String key,
                               java.lang.Object arg1)
Formats a localized value using the provided object.

Parameters:
key - The identifier for the localized text to retrieve,
arg1 - The object to use as {0} when formatting the localized text.
Returns:
Formatted localized text.
See Also:
#format(String, Locale, String, Object[])

format

public java.lang.String format(java.lang.String key,
                               java.lang.Object arg1,
                               java.lang.Object arg2)
Formats a localized value using the provided objects.

Parameters:
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.
Returns:
Formatted localized text.
See Also:
#format(String, Locale, String, Object[])

format

public java.lang.String format(java.lang.String key,
                               java.lang.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.

format

public java.lang.String format(java.lang.String key,
                               java.util.List args)
Formats a localized value using the provided objects. This variation allows for a List so that the velocity ["arg1", "arg2", "arg3"] syntax is supported.

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(java.lang.Object data)
Sets the request to get the Accept-Language header from (reset on each request).

Specified by:
init in interface ApplicationTool
Parameters:
data - initialization data

refresh

public void refresh()
No-op.

Specified by:
refresh in interface ApplicationTool


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.