public interface LocalizationProvider extends Serializable
A LocalizationProvider can be used to obtain the current Locale and for messages localization, using
a message localization key and optional localization arguments.
A LocalizationProvider can be backed by a Vaadin I18NProvider or by the Holon Platform
LocalizationContext. See the create(I18NProvider) and create(LocalizationContext) methods.
A set of static methods are available to obtain the current Locale and/or perform messages
localization using the following strategy:
I18NProvider is available from the current VaadinService, it is used for message
localization.LocalizationContext is used, if it is available as a Context resource and
it is localized.I18NProvider,
LocalizationContext| Modifier and Type | Method and Description |
|---|---|
static LocalizationProvider |
create(com.vaadin.flow.i18n.I18NProvider i18nProvider)
Create a new
LocalizationProvider using given I18NProvider. |
static LocalizationProvider |
create(com.holonplatform.core.i18n.LocalizationContext localizationContext)
Create a new
LocalizationProvider using given LocalizationContext. |
static Optional<Locale> |
getCurrentLocale()
Get the current
Locale, if available. |
Optional<Locale> |
getLocale()
Get the current
Locale, if available. |
static Optional<String> |
getLocalization(Locale locale,
com.holonplatform.core.i18n.Localizable localizable)
Get the message localization for given
locale, using the provided Localizable to obtain the
message localization key (Localizable.getMessageCode()) and the optional localization arguments. |
static Optional<String> |
getLocalization(Locale locale,
String messageCode,
Object... arguments)
Get the message localization for given
locale, using the provided messageCode as
message localization key and the optional localization arguments. |
static String |
getLocalization(Locale locale,
String defaultMessage,
String messageCode,
Object... arguments)
Get the message localization for given
locale, using the provided messageCode as
message localization key and the optional localization arguments. |
Optional<String> |
getMessage(Locale locale,
com.holonplatform.core.i18n.Localizable localizable)
Get the message localization for given
locale, using the provided Localizable to obtain the
message localization key (Localizable.getMessageCode()) and the optional localization arguments. |
default Optional<String> |
getMessage(Locale locale,
String messageCode,
Object... arguments)
Get the message localization for given
locale, using the provided messageCode as
message localization key and the optional localization arguments. |
default String |
getMessage(Locale locale,
String defaultMessage,
String messageCode,
Object... arguments)
Get the message localization for given
locale, using the provided messageCode as
message localization key and the optional localization arguments. |
static Optional<String> |
localize(com.holonplatform.core.i18n.Localizable localizable)
Get the message localization for the current
Locale, using the provided Localizable to obtain the
message localization key (Localizable.getMessageCode()) and the optional localization arguments. |
static Optional<String> |
localize(String messageCode,
Object... arguments)
Get the message localization for the current
Locale, using the provided messageCode as
message localization key and the optional localization arguments. |
static String |
localize(String defaultMessage,
String messageCode,
Object... arguments)
Get the message localization for the current
Locale, using the provided messageCode as
message localization key and the optional localization arguments. |
Optional<Locale> getLocale()
Locale, if available.LocaleOptional<String> getMessage(Locale locale, com.holonplatform.core.i18n.Localizable localizable)
locale, using the provided Localizable to obtain the
message localization key (Localizable.getMessageCode()) and the optional localization arguments.locale - The Locale for which to obtain the message localization (not null)localizable - The Localizable which represents the message to localize (not null)localizable provides a default message
(Localizable.getMessage()) and a message localization is not available, the default message is
returneddefault Optional<String> getMessage(Locale locale, String messageCode, Object... arguments)
locale, using the provided messageCode as
message localization key and the optional localization arguments.locale - The Locale for which to obtain the message localization (not null)messageCode - The message localization key (not null)arguments - Optional message localization argumentsdefault String getMessage(Locale locale, String defaultMessage, String messageCode, Object... arguments)
locale, using the provided messageCode as
message localization key and the optional localization arguments.locale - The Locale for which to obtain the message localization (not null)defaultMessage - The default message to use when a message localization is not available for the provided
Locale and message codemessageCode - The message localization key (not null)arguments - Optional message localization argumentsdefaultMessage if not availablestatic LocalizationProvider create(com.vaadin.flow.i18n.I18NProvider i18nProvider)
LocalizationProvider using given I18NProvider.i18nProvider - The I18NProvider to use for messages localization (not null)LocalizationProvider using given I18NProviderstatic LocalizationProvider create(com.holonplatform.core.i18n.LocalizationContext localizationContext)
LocalizationProvider using given LocalizationContext.localizationContext - The LocalizationContext to use for messages localization (not null)LocalizationProvider using given LocalizationContextstatic Optional<Locale> getCurrentLocale()
Locale, if available.
The current Locale retrieving strategy is:
UI is available and a UI Locale is configured, the UI locale is returned.LocalizationContext is available as a Context resource and it is localized, the
LocalizationContext Locale is returned.I18NProvider is available from the VaadinService, the first Locale from
I18NProvider.getProvidedLocales() is returned, if available.LocaleLocalizationContext.getCurrent()static Optional<String> getLocalization(Locale locale, com.holonplatform.core.i18n.Localizable localizable)
locale, using the provided Localizable to obtain the
message localization key (Localizable.getMessageCode()) and the optional localization arguments.
If a I18NProvider is available from the current VaadinService, it is used for message
localization. Otherwise, the current LocalizationContext is used, if it is available as a Context
resource and it is localized.
locale - The Locale for which to obtain the message localization (not null)localizable - The Localizable which represents the message to localize (not null)localizable provides a default message
(Localizable.getMessage()) and a message localization is not available, the default message is
returnedLocalizationContext.getCurrent()static Optional<String> getLocalization(Locale locale, String messageCode, Object... arguments)
locale, using the provided messageCode as
message localization key and the optional localization arguments.
If a I18NProvider is available from the current VaadinService, it is used for message
localization. Otherwise, the current LocalizationContext is used, if it is available as a Context
resource and it is localized.
locale - The Locale for which to obtain the message localization (not null)messageCode - The message localization key (not null)arguments - Optional message localization argumentsLocalizationContext.getCurrent()static String getLocalization(Locale locale, String defaultMessage, String messageCode, Object... arguments)
locale, using the provided messageCode as
message localization key and the optional localization arguments.
If a I18NProvider is available from the current VaadinService, it is used for message
localization. Otherwise, the current LocalizationContext is used, if it is available as a Context
resource and it is localized.
locale - The Locale for which to obtain the message localization (not null)defaultMessage - The default message to use when a message localization is not available for the provided
Locale and message codemessageCode - The message localization key (not null)arguments - Optional message localization argumentsdefaultMessage if not availableLocalizationContext.getCurrent()static Optional<String> localize(com.holonplatform.core.i18n.Localizable localizable)
Locale, using the provided Localizable to obtain the
message localization key (Localizable.getMessageCode()) and the optional localization arguments.
If a I18NProvider is available from the current VaadinService, it is used for message
localization. Otherwise, the current LocalizationContext is used, if it is available as a Context
resource and it is localized.
The message localization will be performed only if a current Locale is available.
localizable - The Localizable which represents the message to localize (not null)localizable provides a default message
(Localizable.getMessage()) and a message localization is not available, the default message is
returnedgetCurrentLocale()static Optional<String> localize(String messageCode, Object... arguments)
Locale, using the provided messageCode as
message localization key and the optional localization arguments.
If a I18NProvider is available from the current VaadinService, it is used for message
localization. Otherwise, the current LocalizationContext is used, if it is available as a Context
resource and it is localized.
The message localization will be performed only if a current Locale is available.
messageCode - The message localization key (not null)arguments - Optional message localization argumentsgetCurrentLocale()static String localize(String defaultMessage, String messageCode, Object... arguments)
Locale, using the provided messageCode as
message localization key and the optional localization arguments.
If a I18NProvider is available from the current VaadinService, it is used for message
localization. Otherwise, the current LocalizationContext is used, if it is available as a Context
resource and it is localized.
The message localization will be performed only if a current Locale is available.
defaultMessage - The default message to use when a message localization is not available for the provided
Locale and message codemessageCode - The message localization key (not null)arguments - Optional message localization argumentsdefaultMessage if not availablegetCurrentLocale()Copyright © 2020 The Holon Platform. All rights reserved.