- java.lang.Object
-
- io.github.mmm.ui.spi.AbstractUiLocalizer
-
- All Implemented Interfaces:
UiLocalizer
public class AbstractUiLocalizer extends Object implements UiLocalizer
Abstract base implementation ofUiLocalizer
.
-
-
Field Summary
-
Fields inherited from interface io.github.mmm.ui.api.UiLocalizer
KEY_CONFIRM, KEY_DEFAULT_VALIDATION_FAILURE, KEY_ICON, KEY_TOOLTIP
-
-
Constructor Summary
Constructors Constructor Description AbstractUiLocalizer()
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected UiLocalizerBundle
createBundle(String bundleName, Class<?> contextType)
protected UiLocalizerBundle
getBundle()
protected UiLocalizerBundle
getBundle(Object context)
protected String
getBundleName()
protected String
getBundleName(Object context)
Locale
getLocale()
String
localizeOrNull(String key, Object context, boolean contextOnly)
void
setLocale(Locale locale)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.mmm.ui.api.UiLocalizer
localize, localize, localizeOrNull, localizeOrNull
-
-
-
-
Method Detail
-
getLocale
public Locale getLocale()
- Specified by:
getLocale
in interfaceUiLocalizer
- Returns:
- the
Locale
of the current user.
-
setLocale
public void setLocale(Locale locale)
- Parameters:
locale
- new value ofgetLocale()
.
-
getBundleName
protected String getBundleName()
- Returns:
- the
bundle name
of the defaultResourceBundle
for localization.
-
getBundleName
protected String getBundleName(Object context)
- Parameters:
context
- the contextObject
- seelocalizeOrNull(String, Object, boolean)
.- Returns:
- the derived
bundle name
.
-
getBundle
protected UiLocalizerBundle getBundle()
- Returns:
- the
UiLocalizerBundle
for the givenbundle name
.
-
getBundle
protected UiLocalizerBundle getBundle(Object context)
- Parameters:
context
- the contextObject
- seelocalizeOrNull(String, Object, boolean)
.- Returns:
- the
UiLocalizerBundle
for the givenbundleName
.
-
createBundle
protected UiLocalizerBundle createBundle(String bundleName, Class<?> contextType)
- Parameters:
bundleName
- thebundle name
.contextType
- the optionalClass
reflecting the context.- Returns:
- the
UiLocalizerBundle
.
-
localizeOrNull
public String localizeOrNull(String key, Object context, boolean contextOnly)
- Specified by:
localizeOrNull
in interfaceUiLocalizer
- Parameters:
key
- thekey
.context
- the optional context of the key to localize. If notnull
it can identify a more specificResourceBundle
. This allows to define a default localization for a general key but gives the localizer the ability to override this default with a specialized localization in that context. As an example we assume thatkey
is "head". Now if the context is "HTML" or "Human" the ambiguous meaning of the key can be resolved and more appropriate localizations can be chosen. A common case is to localize properties of beans. Here the bean is provided as context so you have the freedom to choose a specific localization for a general property key such as "name" depending on the bean that defines the property without changing the actual UI code. Finally, the context may be a variant such asUiLocalizer.KEY_TOOLTIP
to derive a localized message for a different purpose.contextOnly
- -true
to returnnull
in case no context specific localization is available and omit further fallback,false
otherwise. Whentrue
is provided here, thecontext
should not benull
or this method will simply returnnull
.- Returns:
- the
localized text
. Will benull
if no localization is available.
-
-