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
-
MT_TAG_NATIVE
- Tags the native string if the translation can not be found.
-
MT_THROW_EXCEPTION
- Throw a RuntimeException if the translation can not be found.
-
MT_USE_EMPTY
- Use the empty string if the translation can not be found.
-
MT_USE_NATIVE
- Use the native string if the translation can not be found.
-
Dictionary()
-
-
addLanguageChangeListener(DictionaryListener)
- Adds the specified language change listener to receive language change events from this dictionary.
-
close()
- Closes the dictionary.
-
decodeLocale(Locale)
- Returns the mapped locale
-
doesSupportLocale(Locale)
- Returns true if the dictionary contains the language that the given locale uses.
-
doesSystemSupportLocale(Locale)
- Returns true if the system supports the given locale.
-
finalize()
- Disposes of this dictionary once it is no longer referenced.
-
getActiveLanguage()
- Gets the active language index.
-
getActiveLocale()
- Gets the active locale of the dictionary.
-
getAutoTranslate()
- Gets the auto translation.
-
getBidirectional()
- Gets true of the current language is bidirectional.
-
getBindLocale()
- Gets the locale binding.
-
getCheckLanguage()
- Gets the language checking.
-
getDefaultLanguage()
- Gets the index of the default language.
-
getLanguage()
- Gets the language index.
-
getLanguageCount()
- Gets the amount of the languages in the dictionary.
-
getLanguageData()
- Gets the current language.
-
getLanguageData(int)
- Gets the specified language.
-
getLanguageDatas()
- Gets the all languages.
-
getLanguageLocale()
- Gets the locale of the active language of the dictionary.
-
getLocale()
- Gets the locale of the dictionary.
-
getMissingTranslation()
- Gets the MissingTranslation property.
-
getUpdateDefaultLocale()
- Gets the update default locale.
-
isLanguageBidirectional()
-
-
isLanguageEuropean()
-
-
isLanguageFarEastern()
-
-
isOpen()
- Returns true if the dictionary has been opened.
-
languageChanged(boolean, boolean)
- Dictionary calls this method after the current language has been changed.
-
localeToLanguage(Locale)
- Returns the language index that the given locale uses.
-
open()
- Opens the dictionary.
-
removeLanguageChangeListener(DictionaryListener)
- Removes the language change listener so it no longer receives language change events from this dictionary.
-
setAutoTranslate(boolean)
- Sets the auto translation.
-
setBindLocale(boolean)
- Sets the locale binding.
-
setCheckLanguage(boolean)
- Sets the language checking.
-
setLanguage(int)
- Sets the current language index.
-
setLocale(Locale)
- Sets the locale of the dictionary.
-
setMissingTranslation(int)
- Sets the MissingTranslation property.
-
setUpdateDefaultLocale(boolean)
- Sets the update default locale.
-
translate(String)
- Returns the translations for the given string.
-
translateString(String)
- Returns the translation of the native string in the current language.
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
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
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
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
Dictionary
public Dictionary()
isLanguageEuropean
public boolean isLanguageEuropean()
isLanguageBidirectional
public boolean isLanguageBidirectional()
isLanguageFarEastern
public boolean isLanguageFarEastern()
finalize
public void finalize()
- Disposes of this dictionary once it is no longer referenced.
- Overrides:
- finalize in class Object
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
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
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
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
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.
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.
open
public void open() throws Exception
- Opens the dictionary.
- Throws: Exception
- if an error occurs.
- See Also:
- isOpen, close
isOpen
public boolean isOpen()
- Returns true if the dictionary has been opened.
- See Also:
- open
close
public void close()
- Closes the dictionary.
- See Also:
- open
translate
public String translate(String str)
- Returns the translations for the given string.
- Parameters:
- str - the native string to be translated
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.
getUpdateDefaultLocale
public boolean getUpdateDefaultLocale()
- Gets the update default locale.
setAutoTranslate
public void setAutoTranslate(boolean value) throws Exception
- Sets the auto translation. The default value is true.
- Throws: Exception
- if an error occurs.
getAutoTranslate
public boolean getAutoTranslate()
- Gets the auto translation.
If this is true the dictionary translates every listener after the Language property has been changed.
getBidirectional
public boolean getBidirectional()
- Gets true of the current language is bidirectional.
setMissingTranslation
public void setMissingTranslation(int value)
- Sets the MissingTranslation property.
- See Also:
- MT_USE_NATIVE, MT_USE_EMPTY, MT_TAG_NATIVE, MT_THROW_EXCEPTION
getMissingTranslation
public int getMissingTranslation()
- Gets the MissingTranslation property.
setCheckLanguage
public void setCheckLanguage(boolean value)
- Sets the language checking. The default value is true.
getCheckLanguage
public boolean getCheckLanguage()
- Gets the language checking.
If this is true the dictionary check the language to be set active.
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
getBindLocale
public boolean getBindLocale()
- Gets the locale binding.
If this is true the language and the locale properties are bound.
- See Also:
- getLanguage, getLocale
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
getLanguage
public int getLanguage()
- Gets the language index.
- See Also:
- getActiveLanguage, getLanguageData, getLocale
getActiveLanguage
public int getActiveLanguage()
- Gets the active language index.
- See Also:
- getLanguage
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
getLanguageData
public abstract Language getLanguageData(int index) throws Exception
- Gets the specified language.
- Throws: Exception
- if an error occurs.
- See Also:
- getLanguageCount, getLanguageDatas
getLanguageData
public Language getLanguageData()
- Gets the current language.
- See Also:
- getLanguage
getLanguageDatas
public Language[] getLanguageDatas() throws Exception
- Gets the all languages.
- Throws: Exception
- if an error occurs.
- See Also:
- getLanguageCount, getLanguageData
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
getLocale
public Locale getLocale()
- Gets the locale of the dictionary.
- See Also:
- getLanguage, getLanguageLocale
getActiveLocale
public Locale getActiveLocale()
- Gets the active locale of the dictionary. The mapped locale is never "".
- See Also:
- getLocale, getLanguageLocale
getLanguageLocale
public Locale getLanguageLocale()
- Gets the locale of the active language of the dictionary.
- See Also:
- getLocale, getActiveLocale
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
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
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