All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class multilizer.Dictionary

java.lang.Object
   |
   +----multilizer.Dictionary

public abstract class Dictionary
extends Object
implements Serializable
An abstract class for accessing the dictionary data. Dictionary contains the language and translation data.

The language data contains the information of each language of the dictionary. The translataion data contains the translation of each string in every supported language.

The first language can have a special meaning. This is the case when the language code of the language is "". Such a language is called the native language. It is the language you use to create the application/applet. Native language is never active. The next language (or the first if there is no native language) is the first real language, etc.

The Language property sets the active language. If it is -1 the dictionary chooses the language that matches best to the default locale of the system. The ActiveLanguage property gets the active language. The Locale property sets the active locale. By default the Language and the Locale properties are bound (i.e. if you change either one the other changes to match.) You can break the binding by setting the BindLocale to false.

Dictionary is used to access and store translation data. It does not translate any user interface elements. Use the Translator object do that. One or more translators can listen the dictionary. Whenever the language of the dictionary changes it informs every attached translator about the change letting them to translate their host objects. The listeners does not have to be a translator but any object implementing the DictionaryListener interface.

If you derive a new dictionary from Dictionary class you have to implement the following abstract methods:
- getLanguageCount
- getLanguageData
- translateString

Depending on the dictionary type you might also need to override the following methods:
- open
- close
- languageChanged

To increase performance you might also need to override the following methods:
- getLanguageDatas

See Also:
BinaryDictionary, TextDictionary, ServerDictionary, DatabaseDictionary, Translator

Variable Index

 o MT_TAG_NATIVE
Tags the native string if the translation can not be found.
 o MT_THROW_EXCEPTION
Throw a RuntimeException if the translation can not be found.
 o MT_USE_EMPTY
Use the empty string if the translation can not be found.
 o MT_USE_NATIVE
Use the native string if the translation can not be found.

Constructor Index

 o Dictionary()

Method Index

 o addLanguageChangeListener(DictionaryListener)
Adds the specified language change listener to receive language change events from this dictionary.
 o close()
Closes the dictionary.
 o decodeLocale(Locale)
Returns the mapped locale
 o doesSupportLocale(Locale)
Returns true if the dictionary contains the language that the given locale uses.
 o doesSystemSupportLocale(Locale)
Returns true if the system supports the given locale.
 o finalize()
Disposes of this dictionary once it is no longer referenced.
 o getActiveLanguage()
Gets the active language index.
 o getActiveLocale()
Gets the active locale of the dictionary.
 o getAutoTranslate()
Gets the auto translation.
 o getBidirectional()
Gets true of the current language is bidirectional.
 o getBindLocale()
Gets the locale binding.
 o getCheckLanguage()
Gets the language checking.
 o getDefaultLanguage()
Gets the index of the default language.
 o getLanguage()
Gets the language index.
 o getLanguageCount()
Gets the amount of the languages in the dictionary.
 o getLanguageData()
Gets the current language.
 o getLanguageData(int)
Gets the specified language.
 o getLanguageDatas()
Gets the all languages.
 o getLanguageLocale()
Gets the locale of the active language of the dictionary.
 o getLocale()
Gets the locale of the dictionary.
 o getMissingTranslation()
Gets the MissingTranslation property.
 o getUpdateDefaultLocale()
Gets the update default locale.
 o isLanguageBidirectional()
 o isLanguageEuropean()
 o isLanguageFarEastern()
 o isOpen()
Returns true if the dictionary has been opened.
 o languageChanged(boolean, boolean)
Dictionary calls this method after the current language has been changed.
 o localeToLanguage(Locale)
Returns the language index that the given locale uses.
 o open()
Opens the dictionary.
 o removeLanguageChangeListener(DictionaryListener)
Removes the language change listener so it no longer receives language change events from this dictionary.
 o setAutoTranslate(boolean)
Sets the auto translation.
 o setBindLocale(boolean)
Sets the locale binding.
 o setCheckLanguage(boolean)
Sets the language checking.
 o setLanguage(int)
Sets the current language index.
 o setLocale(Locale)
Sets the locale of the dictionary.
 o setMissingTranslation(int)
Sets the MissingTranslation property.
 o setUpdateDefaultLocale(boolean)
Sets the update default locale.
 o translate(String)
Returns the translations for the given string.
 o translateString(String)
Returns the translation of the native string in the current language.

Variables

 o MT_USE_NATIVE
 public static final int MT_USE_NATIVE
Use the native string if the translation can not be found.

See Also:
MT_USE_EMPTY, MT_TAG_NATIVE, MT_THROW_EXCEPTION
 o MT_USE_EMPTY
 public static final int MT_USE_EMPTY
Use the empty string if the translation can not be found.

See Also:
MT_USE_NATIVE, MT_TAG_NATIVE, MT_THROW_EXCEPTION
 o MT_TAG_NATIVE
 public static final int MT_TAG_NATIVE
Tags the native string if the translation can not be found. For example "house" is tagged to "@house@"

See Also:
MT_USE_NATIVE, MT_USE_EMPTY, MT_THROW_EXCEPTION
 o MT_THROW_EXCEPTION
 public static final int MT_THROW_EXCEPTION
Throw a RuntimeException if the translation can not be found.

See Also:
MT_USE_NATIVE, MT_USE_EMPTY, MT_TAG_NATIVE

Constructors

 o Dictionary
 public Dictionary()

Methods

 o isLanguageEuropean
 public boolean isLanguageEuropean()
 o isLanguageBidirectional
 public boolean isLanguageBidirectional()
 o isLanguageFarEastern
 public boolean isLanguageFarEastern()
 o finalize
 public void finalize()
Disposes of this dictionary once it is no longer referenced.

Overrides:
finalize in class Object
 o translateString
 protected abstract String translateString(String str)
Returns the translation of the native string in the current language. If the translation could not be found returns "".

Parameters:
str - the native string to be translated
 o doesSupportLocale
 protected boolean doesSupportLocale(Locale locale) throws Exception
Returns true if the dictionary contains the language that the given locale uses.

Parameters:
locale - the locale to be checked
Throws: Exception
if an error occurs.
See Also:
doesSystemSupportLocale
 o doesSystemSupportLocale
 public static boolean doesSystemSupportLocale(Locale locale)
Returns true if the system supports the given locale.

Parameters:
locale - the locale to be checked
See Also:
doesSupportLocale
 o decodeLocale
 protected static Locale decodeLocale(Locale locale)
Returns the mapped locale

Parameters:
locale - the locale to be mapped. If this is "" the default locale of the system is used
 o localeToLanguage
 protected int localeToLanguage(Locale locale) throws Exception
Returns the language index that the given locale uses. Returns -1 if the dictionary does not contain any language supporting the locale.

Parameters:
locale - the locale to be used
Throws: Exception
if an error occurs.
 o getDefaultLanguage
 protected int getDefaultLanguage() throws Exception
Gets the index of the default language. This is 1 if the first language is the fake language and 0 i any other case.

Throws: Exception
if an error occurs.
 o open
 public void open() throws Exception
Opens the dictionary.

Throws: Exception
if an error occurs.
See Also:
isOpen, close
 o isOpen
 public boolean isOpen()
Returns true if the dictionary has been opened.

See Also:
open
 o close
 public void close()
Closes the dictionary.

See Also:
open
 o translate
 public String translate(String str)
Returns the translations for the given string.

Parameters:
str - the native string to be translated
 o setUpdateDefaultLocale
 public void setUpdateDefaultLocale(boolean value)
Sets the update default locale. If this is true the dictionary updates the default locale to match the active locale. The default value is true.

 o getUpdateDefaultLocale
 public boolean getUpdateDefaultLocale()
Gets the update default locale.

 o setAutoTranslate
 public void setAutoTranslate(boolean value) throws Exception
Sets the auto translation. The default value is true.

Throws: Exception
if an error occurs.
 o getAutoTranslate
 public boolean getAutoTranslate()
Gets the auto translation. If this is true the dictionary translates every listener after the Language property has been changed.

 o getBidirectional
 public boolean getBidirectional()
Gets true of the current language is bidirectional.

 o setMissingTranslation
 public void setMissingTranslation(int value)
Sets the MissingTranslation property.

See Also:
MT_USE_NATIVE, MT_USE_EMPTY, MT_TAG_NATIVE, MT_THROW_EXCEPTION
 o getMissingTranslation
 public int getMissingTranslation()
Gets the MissingTranslation property.

 o setCheckLanguage
 public void setCheckLanguage(boolean value)
Sets the language checking. The default value is true.

 o getCheckLanguage
 public boolean getCheckLanguage()
Gets the language checking. If this is true the dictionary check the language to be set active.

 o setBindLocale
 public void setBindLocale(boolean value) throws Exception
Sets the locale binding. If the value is set to true, the locale is set to the default locale of the current language. The default value is true.

Throws: Exception
if an error occurs.
See Also:
setLanguage, setLocale
 o getBindLocale
 public boolean getBindLocale()
Gets the locale binding. If this is true the language and the locale properties are bound.

See Also:
getLanguage, getLocale
 o setLanguage
 public void setLanguage(int value) throws Exception
Sets the current language index. The index of the first language of the dictionary is 0, the second 1, etc. If the language and locale has been bound this also sets the locale to match the default locale of the new language.

Throws: Exception
if an error occurs.
See Also:
setLocale, setBindLocale
 o getLanguage
 public int getLanguage()
Gets the language index.

See Also:
getActiveLanguage, getLanguageData, getLocale
 o getActiveLanguage
 public int getActiveLanguage()
Gets the active language index.

See Also:
getLanguage
 o getLanguageCount
 public abstract int getLanguageCount() throws Exception
Gets the amount of the languages in the dictionary.

Throws: Exception
if an error occurs.
See Also:
getLanguageData
 o getLanguageData
 public abstract Language getLanguageData(int index) throws Exception
Gets the specified language.

Throws: Exception
if an error occurs.
See Also:
getLanguageCount, getLanguageDatas
 o getLanguageData
 public Language getLanguageData()
Gets the current language.

See Also:
getLanguage
 o getLanguageDatas
 public Language[] getLanguageDatas() throws Exception
Gets the all languages.

Throws: Exception
if an error occurs.
See Also:
getLanguageCount, getLanguageData
 o setLocale
 public void setLocale(Locale value) throws Exception
Sets the locale of the dictionary. If the language and locale has been bound this also sets the language to match the new locale. If this is "" the default locale is used.

Throws: Exception
if an error occurs.
See Also:
setLanguage, setBindLocale
 o getLocale
 public Locale getLocale()
Gets the locale of the dictionary.

See Also:
getLanguage, getLanguageLocale
 o getActiveLocale
 public Locale getActiveLocale()
Gets the active locale of the dictionary. The mapped locale is never "".

See Also:
getLocale, getLanguageLocale
 o getLanguageLocale
 public Locale getLanguageLocale()
Gets the locale of the active language of the dictionary.

See Also:
getLocale, getActiveLocale
 o addLanguageChangeListener
 public synchronized void addLanguageChangeListener(DictionaryListener l)
Adds the specified language change listener to receive language change events from this dictionary.

Parameters:
l - the language change listener
 o removeLanguageChangeListener
 public synchronized void removeLanguageChangeListener(DictionaryListener l)
Removes the language change listener so it no longer receives language change events from this dictionary.

Parameters:
l - the language change listener
 o languageChanged
 protected void languageChanged(boolean languageChanged,
                                boolean localeChanged) throws Exception
Dictionary calls this method after the current language has been changed. Delivers the language change event to every dictionary listener.

Throws: Exception
if an error occurs.

All Packages  Class Hierarchy  This Package  Previous  Next  Index