org.mailster.gui.prefs.utils
Class LanguageResource

java.lang.Object
  extended by org.mailster.gui.prefs.utils.LanguageResource
All Implemented Interfaces:
java.lang.Comparable<LanguageResource>

public class LanguageResource
extends java.lang.Object
implements java.lang.Comparable<LanguageResource>

Models a container for localized language specific resources.

Author:
Sebastian Machhausen, Edouard De Oliveira

Field Summary
private  java.util.ResourceBundle bundle
          The ResourceBundle associated to the LanguageResource
static java.lang.String KEY_NOT_FOUND
          Predefined String constant for unknown keys which are not part of the LanguageResource
private static java.lang.String TRANSLATION_DATE
          Predefined key to access the date of translation of a LanguageResource
private static java.lang.String TRANSLATION_VERSION
          Predefined key to access the translation version of a LanguageResource
private static java.lang.String TRANSLATOR_KEY
          Predefined key to access the name of the translator of a LanguageResource
 
Constructor Summary
LanguageResource(java.util.ResourceBundle bundle)
          Creates a new LanguageResource which works on the specified ResourceBundle, i.e. extracts the messages from it.
 
Method Summary
 int compareTo(LanguageResource obj)
          Compares this LanguageResource with the specified object for order.
 boolean equals(java.lang.Object obj)
          Tests if this LanguageResource equals the specified obj which also has to be a LanguageResource.
 java.lang.String getFormattedString(java.lang.String key, java.lang.Object[] arguments)
          Gets a localized formatted String from this LanguageResource matching the specified key.
 java.lang.String getFullISOLanguage()
          Returns the lowercase ISO 639 code of this LanguageResource, e.g.
 java.lang.String getISOLanguage()
          Gets the lowercase ISO 639 code of this LanguageResource, e.g.
 java.lang.String getLanguage()
          Gets the full language identifier of this LanguageResource, e.g.
 java.lang.String getLanguage(LanguageResource resource)
          Gets the full language identifier of this LanguageResource, e.g.
 java.lang.String getString(java.lang.String key)
          Gets a localized String from this LanguageResource matching the specified key.
 java.lang.String getTranslationDate()
          Gets the date of translation of this LanguageResource.
 java.lang.String getTranslator()
          Gets the name of the translator of this LanguageResource.
 java.lang.String getVersion()
          Gets the version of this LanguageResource, e.g. the version of the application with which the resource is compliant.
 java.lang.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 java.lang.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 java.lang.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 java.lang.String TRANSLATION_DATE
Predefined key to access the date of translation of a LanguageResource

See Also:
Constant Field Values

TRANSLATION_VERSION

private static final java.lang.String TRANSLATION_VERSION
Predefined key to access the translation version of a LanguageResource

See Also:
Constant Field Values

bundle

private java.util.ResourceBundle bundle
The ResourceBundle associated to the LanguageResource

Constructor Detail

LanguageResource

public LanguageResource(java.util.ResourceBundle bundle)
Creates a new LanguageResource which works on the specified ResourceBundle, i.e. extracts the messages from it.

Parameters:
bundle - the associated ResourceBundle
Method Detail

getFullISOLanguage

public java.lang.String getFullISOLanguage()
Returns the lowercase ISO 639 code of this LanguageResource, e.g. "en" for English. If a country code is available then it will be postfixed to the ISO code e.g. "pt_br" for Brazil.

Returns:
the country string or the lowercase ISO 639 code

getISOLanguage

public java.lang.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

getVersion

public java.lang.String getVersion()
Gets the version of this LanguageResource, e.g. the version of the application with which the resource is compliant.

Returns:
the version of this LanguageResource

getLanguage

public java.lang.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 java.lang.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 java.lang.String getTranslator()
Gets the name of the translator of this LanguageResource.

Returns:
the name of the translator of this LanguageResource

getTranslationDate

public java.lang.String getTranslationDate()
Gets the date of translation of this LanguageResource.

Returns:
the the date of translation of this LanguageResource

getString

public java.lang.String getString(java.lang.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 java.lang.String getFormattedString(java.lang.String key,
                                           java.lang.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 java.lang.String toString()
Converts this LanguageResource to a human readable representation.

Overrides:
toString in class java.lang.Object
Returns:
the language of this LanguageResource as returned by the getLanguage() method


equals

public boolean equals(java.lang.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.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object to test for equality
Returns:
true if this LanguageResource equals the specified obj; false otherwise

compareTo

public int compareTo(LanguageResource 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 java.lang.Comparable<LanguageResource>
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:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this Object.