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

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

public class TranslatorImpl
extends AbstractLogEnabledInstrumentable
implements Translator, 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(Configuration config)
          Configures this component.
 java.lang.String[] getSupportedLanguages(java.lang.String key)
          getSupportedLanguages returns an array of String objects detailing which languages are supported for the given key.
 java.lang.String getTranslation(java.lang.String key, java.lang.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(Configuration config)
               throws 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 Configurable
Parameters:
config - Configuration details
Throws:
ConfigurationException - if an error occurs

getSupportedLanguages

public java.lang.String[] getSupportedLanguages(java.lang.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 java.lang.String getTranslation(java.lang.String key,
                                       java.lang.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 © 1997-2005 The Apache Software Foundation. All Rights Reserved.