Localization Service

There is a Turbine service that makes it easy to add localization support to your application.


# -------------------------------------------------------------------
#  S E R V I C E S
# -------------------------------------------------------------------
# Classes for Turbine Services should be defined here.
# Format: services.[name].classname=[implementing class]
# To specify properties of a service use the following syntax:
# service.[name].[property]=[value]


Resource Bundles

Resource bundles are basically property files. You might have one for the "en" locale thus:

CURRENT_RECORD = Record {0} of {1}

and another for the "en_US" locale thus:


Please see the java.util.ListResourceBundle and java.util.ResourceBundle classes for more information.



Wow. That is a lot of typing. That could be easily shortened to this:


The hard example above was given as an example of using Services. The easy example is the one that you really should be using. Another cool feature of the Localization class is that you can pass in a HttpRequest object like this:

Localization.getString("LABEL_ORGANIZATION", data.getRequest());

This has the added effect of using the Accept-Language HTTP header to determine which language to display based on what setting the user has defined in the browser. Can you say Dynamic Localization? ;-)

The Localization class also supports the formatting of localized strings containing parameters, such as in

    recno, all);

This actually doesn't look too nice, however the call using the LocalizationTool from a Velocity template (see below) just deflates to

$l10n.format("CURRENT_RECORD", $recno, $all);

Usage from a template

Turbine provides a Pull tool to make it very easy to access localized text from within your templates. To configure this you need to add the following to your TurbineResouces.properties:

tool.request.l10n = org.apache.turbine.services.localization.LocalizationTool

You can then use it in your templates thus:


A string with arguments can be used thus:

// No arguments
// One argument
$l10n.format("STRING_KEY_ONE_ARG" "arg1")
// Two arguments
$l10n.format("CURRENT_RECORD" "1", "5")
// Two arguments
$l10n.format("STRING_KEY_3_OR_MORE_ARGS" ["arg1", "arg2", "arg3"])