|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.livotov.tpt.i18n.Dictionary
public class Dictionary
A dictionary object, that holds translation data for all instances of a single application. In most cases this class shoud not be instantiated directly, use a TM front-end instead.
Field Summary | |
---|---|
protected java.util.HashMap<java.lang.String,java.util.Properties> |
countries
Contains references to loaded properties files for the set of countries |
private java.lang.String |
defaultLanguage
Default language. |
protected java.util.HashMap<java.lang.String,java.util.Properties> |
languages
Contains references to loaded properties files for the set of languages |
Constructor Summary | |
---|---|
Dictionary()
|
Method Summary | |
---|---|
void |
clear()
|
protected java.lang.String |
extractCountryCodeFromString(java.lang.String name)
|
protected java.lang.String |
extractLanguageCodeFromString(java.lang.String name)
|
java.lang.String |
get(com.vaadin.Application app,
java.lang.String key)
Provides a translation of the given key for the given application instance, using this instance language (locale). |
java.lang.String |
get(java.util.Locale locale,
java.lang.String key)
Provides a translation of the given key for the given locale |
java.lang.String |
get(java.lang.String key)
Provides a translation of the given key for the current application instance, using this instance language (locale). |
java.lang.String |
get(java.lang.String lang,
java.lang.String country,
java.lang.String key)
Provides a translation of the given key for the given language and country codes |
java.lang.String |
getDefaultLanguage()
Provides current default language 2 letter code that is used by the dictionary in case key being queried is not found in the target language. |
private java.util.Properties |
getLanguageBundle(java.lang.String lang,
java.lang.String country)
|
void |
loadTranslationFilesFromThemeFolder(java.io.File themeFolder)
|
void |
loadTranslationsFromLanguageDirectory(java.io.File folder)
|
void |
loadWords(java.lang.String lang,
java.lang.String country,
java.io.File file,
boolean overwrite)
Loads data into dictionary from a reader object. |
void |
loadWords(java.lang.String lang,
java.lang.String country,
java.io.InputStream data)
Loads data into dictionary from a property file. |
void |
loadWords(java.lang.String lang,
java.lang.String country,
java.io.Reader data)
Loads data into dictionary from a reader object. |
void |
loadWords(java.lang.String lang,
java.lang.String country,
java.net.URL resource,
boolean overwrite)
Loads data into dictionary from a property file. |
void |
setDefaultLanguage(java.lang.String defaultLanguage)
Sets the new current language 2 letter code. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.HashMap<java.lang.String,java.util.Properties> languages
protected java.util.HashMap<java.lang.String,java.util.Properties> countries
private java.lang.String defaultLanguage
Constructor Detail |
---|
public Dictionary()
Method Detail |
---|
public java.lang.String get(java.lang.String key)
key
- key to get translated string for
public java.lang.String get(com.vaadin.Application app, java.lang.String key)
app
- application instance. It is used to extact locale to be used in translationkey
- key to get translated string for
public java.lang.String get(java.util.Locale locale, java.lang.String key)
locale
- localekey
- key to get translated string for
public java.lang.String get(java.lang.String lang, java.lang.String country, java.lang.String key)
lang
- language 2 letter code. Cannot be nullor emptycountry
- country 2 letter code. Can be null or empty, in this case, generic translation
for the country is used.key
- key to get translated string for
public void loadWords(java.lang.String lang, java.lang.String country, java.net.URL resource, boolean overwrite) throws java.io.IOException
lang
- 2 letter language code, the file being loaded refers to. Cannot be null or
empty.country
- 2 letter country code, the file being loaded rerefs to. Can be null or
empty.resource
- URL to a property file from classpath resource. Note, that resource contents must
be in UTF-8 encodingoverwrite
- if set to false, dictionary will allow any unique url to be loaded only
once. This is useful ehrn you load translations in the application init or
constructor method, which is called for all sessions. Having overwrite
parameter set to false, you prevents spending system resources for unneeded
loads of the same data.
java.io.IOException
- if any IO error occurspublic void loadWords(java.lang.String lang, java.lang.String country, java.io.InputStream data) throws java.io.IOException
lang
- 2 letter language code, the file being loaded refers to. Cannot be null or
empty.country
- 2 letter country code, the file being loaded rerefs to. Can be null or empty.data
- input stream for the translation property file contents to be loaded.
java.io.IOException
- if any IO error occurspublic void loadWords(java.lang.String lang, java.lang.String country, java.io.Reader data) throws java.io.IOException
lang
- 2 letter language code, the file being loaded refers to. Cannot be null or
empty.country
- 2 letter country code, the file being loaded rerefs to. Can be null or empty.data
- reader instance for the translation property file contents to be loaded.
java.io.IOException
- if any IO error occurspublic void loadWords(java.lang.String lang, java.lang.String country, java.io.File file, boolean overwrite) throws java.io.IOException
lang
- 2 letter language code, the file being loaded refers to. Cannot be null or
empty.country
- 2 letter country code, the file being loaded rerefs to. Can be null or empty.file
- i18n file. Note, the contents must be in UTF-8 encoding.
java.io.IOException
- if any IO error occursprivate java.util.Properties getLanguageBundle(java.lang.String lang, java.lang.String country)
public java.lang.String getDefaultLanguage()
public void setDefaultLanguage(java.lang.String defaultLanguage)
defaultLanguage
- new 2 letter code to be used as a current language.public void loadTranslationFilesFromThemeFolder(java.io.File themeFolder) throws java.io.IOException
java.io.IOException
public void loadTranslationsFromLanguageDirectory(java.io.File folder) throws java.io.IOException
java.io.IOException
protected java.lang.String extractCountryCodeFromString(java.lang.String name)
protected java.lang.String extractLanguageCodeFromString(java.lang.String name)
public void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |