org.apache.avalon.fortress.examples.components
Class TranslatorImpl

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
          extended by org.apache.avalon.fortress.examples.components.TranslatorImpl
All Implemented Interfaces:
Translator, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.excalibur.instrument.Instrumentable

public class TranslatorImpl
extends org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
implements Translator, org.apache.avalon.framework.configuration.Configurable

Simple implementation of the Translator component, which maintains a simple mapping of keys to translated values, created during configuration.

Configuration format:

 <translations>
   <entry key="hello-world">
    <value language="Deutsch">Hallo Welt</value>
    <value language="English">Hello World</value>
   </entry>
 </translations>
 

Version:
CVS $Revision: 1.10 $ $Date: 2004/02/24 22:31:21 $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.avalon.fortress.examples.components.Translator
ROLE
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
TranslatorImpl()
          Create a new TranslatorImpl.
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration config)
          Configures this component.
 String[] getSupportedLanguages(String key)
          getSupportedLanguages returns an array of String objects detailing which languages are supported for the given key.
 String getTranslation(String key, String language)
          getTranslation obtains a translation for a given key in a given language.
 
Methods inherited from class org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
addChildInstrumentable, addInstrument, getChildInstrumentables, getInstrumentableName, getInstruments, setInstrumentableName
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TranslatorImpl

public TranslatorImpl()
Create a new TranslatorImpl.

Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration config)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configures this component. Reads configuration information from container and appropriately sets up the internal mapping array. Configuration syntax is specified in the class header.

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
config - Configuration details
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occurs

getSupportedLanguages

public String[] getSupportedLanguages(String key)
getSupportedLanguages returns an array of String objects detailing which languages are supported for the given key.

Specified by:
getSupportedLanguages in interface Translator
Parameters:
key - a String value identifying a translation
Returns:
a String[] array containing available language translations for the given key

getTranslation

public String getTranslation(String key,
                             String language)
getTranslation obtains a translation for a given key in a given language. The language parameter must be listed in getSupportedLanguages.

Specified by:
getTranslation in interface Translator
Parameters:
key - a String value identifying a translation
language - a String value identifying the language
Returns:
translated text


Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.