- 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 UiLocalizerBundlecreateBundle(String bundleName, Class<?> contextType)protected UiLocalizerBundlegetBundle()protected UiLocalizerBundlegetBundle(Object context)protected StringgetBundleName()protected StringgetBundleName(Object context)LocalegetLocale()StringlocalizeOrNull(String key, Object context, boolean contextOnly)voidsetLocale(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:
getLocalein interfaceUiLocalizer- Returns:
- the
Localeof the current user.
-
setLocale
public void setLocale(Locale locale)
- Parameters:
locale- new value ofgetLocale().
-
getBundleName
protected String getBundleName()
- Returns:
- the
bundle nameof the defaultResourceBundlefor 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
UiLocalizerBundlefor the givenbundle name.
-
getBundle
protected UiLocalizerBundle getBundle(Object context)
- Parameters:
context- the contextObject- seelocalizeOrNull(String, Object, boolean).- Returns:
- the
UiLocalizerBundlefor the givenbundleName.
-
createBundle
protected UiLocalizerBundle createBundle(String bundleName, Class<?> contextType)
- Parameters:
bundleName- thebundle name.contextType- the optionalClassreflecting the context.- Returns:
- the
UiLocalizerBundle.
-
localizeOrNull
public String localizeOrNull(String key, Object context, boolean contextOnly)
- Specified by:
localizeOrNullin interfaceUiLocalizer- Parameters:
key- thekey.context- the optional context of the key to localize. If notnullit 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 thatkeyis "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_TOOLTIPto derive a localized message for a different purpose.contextOnly- -trueto returnnullin case no context specific localization is available and omit further fallback,falseotherwise. Whentrueis provided here, thecontextshould not benullor this method will simply returnnull.- Returns:
- the
localized text. Will benullif no localization is available.
-
-