Package com.suncode.pwfl.translation
Class AbstractTranslator
java.lang.Object
com.suncode.pwfl.translation.AbstractTranslator
- All Implemented Interfaces:
ClassLoaderTranslator
,PackageTranslator
,Translator
- Direct Known Subclasses:
EmptyTranslator
,PropertiesTranslator
@Api
public abstract class AbstractTranslator
extends Object
implements PackageTranslator, ClassLoaderTranslator
Common Translator implementation.
- Author:
- Cezary Kozar 11 sie 2015
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTranslatedPackage
(String packageName) Adds package, that contains classes which should be translated with this translator.boolean
getLocalizedString
(String key) Creates LocalizedString with given key.getLocalizedString
(String key, Object... args) Creates LocalizedString with given key and message arguments.getLocalizedString
(String key, String defaultValue) Creates LocalizedString with given key and default value.getLocalizedString
(String key, String[] fallbackKeys, String defaultValue) Creates LocalizedString with given key, fallback keys and default value.getLocalizedString
(String key, String[] fallbackKeys, String defaultValue, Locale locale, Object... args) Creates LocalizedString.getLocalizedString
(String key, String defaultValue, Object... args) Creates LocalizedString with given key, default value and message arguments.getLocalizedString
(String key, String defaultValue, Locale locale) Creates LocalizedString with given key, locale and default value.getLocalizedString
(String key, String defaultValue, Locale locale, Object... args) Creates LocalizedString with given key, default value, locale and message arguments.getLocalizedString
(String key, Locale locale) Creates LocalizedString with given key and locale.getLocalizedString
(String key, Locale locale, Object... args) Creates LocalizedString with given key, locale and message arguments.getMessage
(String key) Return translated message for given key using current user locale.getMessage
(String key, Object... args) Return translated message for given key and arguments using current user locale.getMessage
(String key, Locale locale) Return translated message for given key and locale.getMessage
(String key, Locale locale, Object... args) Return translated message for given key, locale and arguments.int
hashCode()
protected abstract String
resolveMessage
(String key, Locale locale, Object... args) void
setParent
(Translator parent) Sets this translator parent.void
setTranslatedClassLoader
(ClassLoader classLoader) ClassLoader, for which this translator will be registered.Packages, for which this translator will be registered.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.suncode.pwfl.translation.Translator
getMessages
-
Constructor Details
-
AbstractTranslator
public AbstractTranslator() -
AbstractTranslator
-
-
Method Details
-
addTranslatedPackage
Adds package, that contains classes which should be translated with this translator.- Parameters:
packageName
- package name
-
setTranslatedClassLoader
-
setParent
Sets this translator parent. -
getParent
-
resolveMessage
protected abstract String resolveMessage(String key, Locale locale, Object... args) throws NoTranslationException - Throws:
NoTranslationException
-
translatedPackages
Description copied from interface:PackageTranslator
Packages, for which this translator will be registered.- Specified by:
translatedPackages
in interfacePackageTranslator
-
translatedClassLoader
Description copied from interface:ClassLoaderTranslator
ClassLoader, for which this translator will be registered.- Specified by:
translatedClassLoader
in interfaceClassLoaderTranslator
-
getMessage
Description copied from interface:Translator
Return translated message for given key, locale and arguments.- Specified by:
getMessage
in interfaceTranslator
- Parameters:
key
- message keylocale
- localeargs
- optional placeholder arguments (e.g. {0} {1})- Returns:
- translated message for given key
- Throws:
NoTranslationException
-
getMessage
Description copied from interface:Translator
Return translated message for given key using current user locale.- Specified by:
getMessage
in interfaceTranslator
- Throws:
NoTranslationException
- See Also:
-
getMessage
Description copied from interface:Translator
Return translated message for given key and locale.- Specified by:
getMessage
in interfaceTranslator
- Throws:
NoTranslationException
- See Also:
-
getMessage
Description copied from interface:Translator
Return translated message for given key and arguments using current user locale.- Specified by:
getMessage
in interfaceTranslator
- Throws:
NoTranslationException
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key and default value.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key, fallback keys and default value.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key and locale.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key, locale and default value.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key and message arguments.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key, default value and message arguments.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
Description copied from interface:Translator
Creates LocalizedString with given key, locale and message arguments.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
public LocalizedString getLocalizedString(String key, String defaultValue, Locale locale, Object... args) Description copied from interface:Translator
Creates LocalizedString with given key, default value, locale and message arguments.- Specified by:
getLocalizedString
in interfaceTranslator
- See Also:
-
getLocalizedString
public LocalizedString getLocalizedString(String key, String[] fallbackKeys, String defaultValue, Locale locale, Object... args) Description copied from interface:Translator
Creates LocalizedString.- Specified by:
getLocalizedString
in interfaceTranslator
- Parameters:
key
- message keyfallbackKeys
- fallback keysdefaultValue
- default value returned when no translation could be foundlocale
- localeargs
- optional message arguments (e.g. {0} {1})- Returns:
- LocalizedString
- See Also:
-
equals
-
hashCode
public int hashCode()
-