|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.essex.common.lang.Translator
public class Translator
Class to provide translation facilities, using locales, resource bundles and
properties files. This class is a variation on a singleton class, all references to it
should be obtained by using the getInstance() method, which returns (the same)
static instance. However a singleton will be created for each resource base name.
This allows you to have multiple subsystems each with their own resource base name
and corresponding file. Yet at the same time still treat this class as a singleton.
This is simply impleemted as a HashMap mapping resource base name to Translator
instances. If the hashmap doesn't contain the resource base name then a translator is
instantiated otherwise you get the old one.-
Locales and resource bundles basically just provide a hash
map that maps keys to values. For each available locale their is a different
hashmap. These different maps have the same keys but differnt sets of values,
there is one for each language available.
By default this will search for the resources on the classpath and will use the
default resource base name of "Resources". The only default locale it will
search for is Locale.ENGLISH
PropertyResourceBundle
,
Locale
Field Summary | |
---|---|
static java.util.Locale |
DEFAULT_LOCALE
The default locale to use this is Locale.ENGLISH |
static java.lang.String |
DEFAULT_RESOURCE_BASE_NAME
The default resource base name to search for if none is given - this is "Resources" |
Method Summary | |
---|---|
java.lang.String |
get(java.util.Locale locale,
java.lang.String key)
Given a locale and a STRING key this returns the string for that key using that locale. |
java.lang.String |
get(java.lang.String key)
Given a locale and a STRING key this returns the string for that key using the locale obtained by calling DEFAULT_LOCALE . |
static Translator |
getInstance()
This uses the default locales |
static Translator |
getInstance(java.lang.String resourceBaseName)
|
static Translator |
getInstance(java.lang.String resourceBaseName,
java.io.File directoryToLoadFrom)
|
static Translator |
getInstance(java.lang.String resourceBaseName,
java.io.File directoryToLoadFrom,
java.util.Locale[] locales)
|
static void |
main(java.lang.String[] args)
Used for testing |
static void |
setDefaultLocale(java.util.Locale defaultLocale)
|
boolean |
supportsLanguage(java.util.Locale locale)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_RESOURCE_BASE_NAME
public static java.util.Locale DEFAULT_LOCALE
Locale.ENGLISH
Method Detail |
---|
public java.lang.String get(java.lang.String key)
DEFAULT_LOCALE
.
key
-
public java.lang.String get(java.util.Locale locale, java.lang.String key)
locale
- - The locale to use to 'translate' the given keykey
- - The key of the required translationpublic boolean supportsLanguage(java.util.Locale locale)
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
public static Translator getInstance()
public static Translator getInstance(java.lang.String resourceBaseName, java.io.File directoryToLoadFrom)
resourceBaseName
- - The resource base name files are then called for eg/
%RESOURCE_BASE_NAME%_en_EN.propertiesdirectoryToLoadFrom
- - The root directory where the resources are located, if this
is null then the classpath will be used
public static Translator getInstance(java.lang.String resourceBaseName)
resourceBaseName
- - The resource base name files are then called for eg/
%RESOURCE_BASE_NAME%_en_EN.properties
public static Translator getInstance(java.lang.String resourceBaseName, java.io.File directoryToLoadFrom, java.util.Locale[] locales) throws java.lang.Exception
resourceBaseName
- - The resource base name files are then called for eg/
%RESOURCE_BASE_NAME%_en_EN.propertiesdirectoryToLoadFrom
- - The root directory where the resources are located, if this
is null then the classpath will be used
java.lang.Exception
- - If it cannot find or load the resource filespublic static void setDefaultLocale(java.util.Locale defaultLocale)
defaultLocale
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |