net.sourceforge.java.util.i18n
Class LanguageResource

java.lang.Object
  extended bynet.sourceforge.java.util.i18n.LanguageResource
All Implemented Interfaces:
Comparable

public class LanguageResource
extends Object
implements Comparable

Models a container for localized language specific resources.

Author:
Sebastian Machhausen

Field Summary
private  ResourceBundle bundle
           The ResourceBundle associated to the LanguageResource
static String KEY_NOT_FOUND
           Predefined String constant for unknown keys which are not part of the LanguageResource
private static String TRANSLATION_DATE
           Predefined key to access the date of translation of a LanguageResource
private static String TRANSLATOR_KEY
           Predefined key to access the name of the translator of a LanguageResource
 
Constructor Summary
LanguageResource(ResourceBundle bundle)
           Creates a new LanguageResource whcih works on the specified ResourceBundle, i.e. extracts the messages from it.
 
Method Summary
 int compareTo(Object obj)
           Compares this LanguageResource with the specified object for order.
 boolean equals(Object obj)
           Tests if this LanguageResource equals the specified obj which also has to be a LanguageResource.
 String getFormattedString(String key, Object[] arguments)
           Gets a localized formatted String from this LanguageResource matching the specified key.
 String getISOLanguage()
           Gets the lowercase ISO 639 code of this LanguageResource, e.g.
 String getLanguage()
           Gets the full language identifier of this LanguageResource, e.g.
 String getLanguage(LanguageResource resource)
           Gets the full language identifier of this LanguageResource, e.g.
 String getString(String key)
           Gets a localized String from this LanguageResource matching the specified key.
 String getTranslationDate()
           Gets the date of translation of this LanguageResource.
 String getTranslator()
           Gets the name of the translator of this LanguageResource.
 String toString()
           Converts this LanguageResource to a human readable representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_NOT_FOUND

public static final String KEY_NOT_FOUND

Predefined String constant for unknown keys which are not part of the LanguageResource

See Also:
Constant Field Values

TRANSLATOR_KEY

private static final String TRANSLATOR_KEY

Predefined key to access the name of the translator of a LanguageResource

See Also:
Constant Field Values

TRANSLATION_DATE

private static final String TRANSLATION_DATE

Predefined key to access the date of translation of a LanguageResource

See Also:
Constant Field Values

bundle

private ResourceBundle bundle

The ResourceBundle associated to the LanguageResource

Constructor Detail

LanguageResource

public LanguageResource(ResourceBundle bundle)

Creates a new LanguageResource whcih works on the specified ResourceBundle, i.e. extracts the messages from it.

Parameters:
bundle - the associated ResourceBundle
Method Detail

getISOLanguage

public String getISOLanguage()

Gets the lowercase ISO 639 code of this LanguageResource, e.g. "en" for English.

Returns:
the lowercase ISO 639 code of this LanguageResource

getLanguage

public String getLanguage()

Gets the full language identifier of this LanguageResource, e.g. "English". If possible, the name returned will be localized according to the current default LanguageResource. For example, if the LanguageResource is fr and the default LanguageResource is en, getLanguage(LanguageResource) will return "French"; if the LanguageResource is en and the default LanguageResource is fr, getLanguage(LanguageResource) will return "anglais".

Returns:
the full language identifier of this LanguageResource
See Also:
getLanguage(LanguageResource)

getLanguage

public String getLanguage(LanguageResource resource)

Gets the full language identifier of this LanguageResource, e.g. "English". If possible, the name returned will be localized according to resource. For example, if the LanguageResource is fr and resource is en, getLanguage(LanguageResource) will return "French"; if the LanguageResource is en and resource is fr, getLanguage(LanguageResource) will return "anglais".

Parameters:
resource - the LanguageResource to use for getting the language
Returns:
the full language identifier of this LanguageResource
See Also:
getLanguage()

getTranslator

public String getTranslator()

Gets the name of the translator of this LanguageResource.

Returns:
the name of the translator of this LanguageResource

getTranslationDate

public String getTranslationDate()

Gets the date of translation of this LanguageResource.

Returns:
the the date of translation of this LanguageResource

getString

public String getString(String key)

Gets a localized String from this LanguageResource matching the specified key.

Parameters:
key - the key of the localized String to access
Returns:
the localized String; KEY_NOT_FOUND if the key is not part of this LanguageResource

getFormattedString

public String getFormattedString(String key,
                                 Object[] arguments)

Gets a localized formatted String from this LanguageResource matching the specified key.

Parameters:
key - the key of the localized String to access
arguments - a list of parameters to use for formatting
Returns:
the localized formatted String; KEY_NOT_FOUND if the key is not part of this LanguageResource

toString

public String toString()

Converts this LanguageResource to a human readable representation.

Returns:
the language of this LanguageResource as returned by the getLanguage() method


equals

public boolean equals(Object obj)

Tests if this LanguageResource equals the specified obj which also has to be a LanguageResource. Two LanguageResources are considered equal if both have the same language as returned by the getLanguage() method.

Parameters:
obj - the Object to test for equality
Returns:
true if this LanguageResource equals the specified obj; false otherwise

compareTo

public int compareTo(Object obj)

Compares this LanguageResource with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.

Specified by:
compareTo in interface Comparable
Parameters:
obj - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this LanguageResource is less than, equal to, or greater than the specified object.
Throws:
ClassCastException - if the specified object's type prevents it from being compared to this Object.