Localization Service

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

Configuration

# -------------------------------------------------------------------
# 
#  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]

services.GlobalCacheService.classname=org.apache.turbine.services.cache.TurbineGlobalCacheService
.
.
.

Usage


TurbineServices.getInstance().getService(LocalizationService.LOCALIZATION)
    .getString("DISPLAYPROJECTS_TITLE");

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


Localization.getString("DISPLAYPROJECTS_TITLE");

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 RunData object like this:


Localization.getString(data, "DISPLAYPROJECTS_TITLE");

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? ;-)

For creating the file where you get the value of the String, please see the java.util.ListResourceBundle and java.util.ResourceBundle classes for more information. Jyve also contains example usage of this code because that was the first place where this code was originally developed.