cdox.util
Class Localizer

java.lang.Object
  extended bycdox.util.Localizer

public class Localizer
extends java.lang.Object

This is a wrapper class that handles several localized language files. To use this, you must have some language files somewhere. If you have a package com.microsoft.stupid you could have a dir called lang there with a language file `deu'. Then you would call new Localizer() or setLang() with (Locale.GERMAN,"/com/microsoft/stupid/lang/") to initialize this class.

The language files must be named according to ISO 639-2/T (three letter language code), english would be "eng", german "deu" etc.

The language files can also be used to provide you with keystrokes. If provideKeystrokes is set to true, every string that is returned will be stripped from & chars. If set to false (which is the default), the & chars are also returned.

Version:
May 22nd 2002
Author:
Rutger Bezema, Andreas Schmitz

Constructor Summary
Localizer(java.util.Locale loc, java.lang.String path)
          Constructs a new Localizer.
Localizer(java.lang.String lng, java.lang.String path)
          Creates a new Localizer instance.
 
Method Summary
 java.lang.String get(java.lang.String key)
          Returns the localized String mapping the key.
 java.lang.String get(java.lang.String key, java.lang.String[] param)
          Returns the localized String mapping the key.
 java.util.Properties getAvailableLanguages()
          Returns the available languages.
 java.lang.String getLanguageCode()
          Returns the ISO3 language code for this localizer.
static Localizer getLocalizer(java.lang.String language)
          This method just returns a Localizer for the utilities packages.
 char getStroke(java.lang.String key)
          Returns the key stroke for this object or ' ', if none has been specified.
 void provideKeystrokes(boolean yes)
          Sets whether the Localizer should provide you with keystrokes and strip the & characters or not.
 boolean providesKeystrokes()
          Returns whether the Localizer provides you with keystrokes and strips the & character or not.
 boolean setLang(java.util.Locale loc, java.lang.String path)
          Sets the new language for this Localizer.
 boolean setLang(java.lang.String path)
          Sets the new language for this Localizer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Localizer

public Localizer(java.util.Locale loc,
                 java.lang.String path)
          throws java.io.IOException
Constructs a new Localizer. Throws an IOException if the language file had not been found.

Parameters:
loc - the locale which language should be used
path - the path to the new language file
Throws:
java.io.IOException - if no language file for loc had been found

Localizer

public Localizer(java.lang.String lng,
                 java.lang.String path)
          throws java.io.IOException
Creates a new Localizer instance.

Parameters:
lng - a String value indicating the language.
path - a String value indicating the package path.
Throws:
java.io.IOException - if an error occurs.
Method Detail

setLang

public boolean setLang(java.util.Locale loc,
                       java.lang.String path)
Sets the new language for this Localizer. Returns whether the new language exists or not.

Parameters:
loc - the locale which language should be used
path - the path to the new language file
Returns:
true if the new language had set, otherwise false.

setLang

public boolean setLang(java.lang.String path)
Sets the new language for this Localizer. Returns whether the new language exists or not.

Parameters:
path - the path to the new language file, ending with the iso3 language code.
Returns:
true if the new language had set, otherwise false.

getLanguageCode

public java.lang.String getLanguageCode()
Returns the ISO3 language code for this localizer.

Returns:
the code.

getAvailableLanguages

public java.util.Properties getAvailableLanguages()
Returns the available languages. There must exist a properties file named availablelanguages in the languages package where all other language files are for this to work. If no such file exists, an empty properties object will be returned.

Returns:
a properties object with the ISO3-Languages as values and the display languages as keys.

provideKeystrokes

public void provideKeystrokes(boolean yes)
Sets whether the Localizer should provide you with keystrokes and strip the & characters or not.

Parameters:
yes - true if you want the keystrokes.

providesKeystrokes

public boolean providesKeystrokes()
Returns whether the Localizer provides you with keystrokes and strips the & character or not.

Returns:
true, if he does.

getStroke

public char getStroke(java.lang.String key)
Returns the key stroke for this object or ' ', if none has been specified.

Parameters:
key - the key.
Returns:
the char.

get

public java.lang.String get(java.lang.String key)
Returns the localized String mapping the key. Please note that possible & charachters will be removed from the String.

Parameters:
key - the key
Returns:
the String

get

public java.lang.String get(java.lang.String key,
                            java.lang.String[] param)
Returns the localized String mapping the key. The second parameter contains the Strings that should be used to replace the parameters. Such parameters occur in the language file as %1% %2% %3% etc. This method will throw an exception if anything goes wrong (I will make proper error handling later). Please note that possible & characters are removed from the String.

Parameters:
key - the key
param - the replacements.
Returns:
the String

getLocalizer

public static Localizer getLocalizer(java.lang.String language)
This method just returns a Localizer for the utilities packages. One should not use this one outside the util package. Errors will be logged into the ErrorHandler log, if it exists.

Parameters:
language - the language for the localizer.
Returns:
the Localizer or null, if no suitable language file was found.