com.lyrisoft.util.i18n
Class Translator

java.lang.Object
  |
  +--com.lyrisoft.util.i18n.Translator

public class Translator
extends java.lang.Object

This class "translates" things by using a specially formatted varibles that can be substituted. A properties file, which is really just key/value pairs, might look something like this:

 user.not.found=The user, {0}, was not found.
 invited={0} has invited you to {1}
 
{0} through {n} can be used inside of any message string to allow variable substition.

Given the properties file above, this call:

getMessage("invited", "jack", "jack's room");
Would return
Jack has invited you to jack's room
The "translation" part is actually a manual step, in that somebody has to actually create a translated version of the properties file(s).


Constructor Summary
Translator()
           
Translator(java.util.Properties p)
          Construct a Translator that will used the specified Properties.
 
Method Summary
 java.lang.String getMessage(java.lang.String key)
          Get a message without any variable substition.
 java.lang.String getMessage(java.lang.String key, java.lang.String arg1)
          Get a message and substitute {0} with arg1
 java.lang.String getMessage(java.lang.String key, java.lang.String[] args)
          The most general case of substituting variables: {0} thru {n} are substibuted with args[0] thru args[n].
 java.lang.String getMessage(java.lang.String key, java.lang.String arg1, java.lang.String arg2)
          Get a message and substitute {0} and {1} with arg1 and arg2
 java.lang.String getMessage(java.lang.String key, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3)
          Get a message and substitute {0}, {1}, and {2} with arg1, arg2, and arg3.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Translator

public Translator(java.util.Properties p)
Construct a Translator that will used the specified Properties.

Translator

public Translator()
Method Detail

getMessage

public java.lang.String getMessage(java.lang.String key)
Get a message without any variable substition.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.String arg1)
Get a message and substitute {0} with arg1

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.String arg1,
                                   java.lang.String arg2)
Get a message and substitute {0} and {1} with arg1 and arg2

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.String arg1,
                                   java.lang.String arg2,
                                   java.lang.String arg3)
Get a message and substitute {0}, {1}, and {2} with arg1, arg2, and arg3.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.String[] args)
The most general case of substituting variables: {0} thru {n} are substibuted with args[0] thru args[n].


Copyright © 2000-2002 Taso Lyristis