com.holonplatform.vaadin.flow.i18n

## Interface LocalizationProvider

- All Superinterfaces:
    Serializable

      public interface LocalizationProvider
      extends Serializable

  Message localization provider.

  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:

  - 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.
  Since:
    5.2.0
  See Also:
    `I18NProvider`, `LocalizationContext`

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    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.

- - ### Method Detail

    - #### getLocale

          Optional<Locale> getLocale()

      Get the current `Locale`, if available.
      Returns:
        Optional current `Locale`

    - #### getMessage

          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.
      Parameters:
        `locale` - The `Locale` for which to obtain the message localization (not null)
        `localizable` - The `Localizable` which represents the message to localize (not null)
      Returns:
        The localized message, if available. If the given `localizable` provides a default message (`Localizable.getMessage()`) and a message localization is not available, the default message is returned

    - #### getMessage

          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.
      Parameters:
        `locale` - The `Locale` for which to obtain the message localization (not null)
        `messageCode` - The message localization key (not null)
        `arguments` - Optional message localization arguments
      Returns:
        The localized message, if available

    - #### getMessage

          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.
      Parameters:
        `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 code
        `messageCode` - The message localization key (not null)
        `arguments` - Optional message localization arguments
      Returns:
        The localized message, or the `defaultMessage` if not available

    - #### create

          static LocalizationProvider create(com.vaadin.flow.i18n.I18NProvider i18nProvider)

      Create a new `LocalizationProvider` using given `I18NProvider`.
      Parameters:
        `i18nProvider` - The `I18NProvider` to use for messages localization (not null)
      Returns:
        A new `LocalizationProvider` using given `I18NProvider`

    - #### create

          static LocalizationProvider create(com.holonplatform.core.i18n.LocalizationContext localizationContext)

      Create a new `LocalizationProvider` using given `LocalizationContext`.
      Parameters:
        `localizationContext` - The `LocalizationContext` to use for messages localization (not null)
      Returns:
        A new `LocalizationProvider` using given `LocalizationContext`

    - #### getCurrentLocale

          static Optional<Locale> getCurrentLocale()

      Get the current `Locale`, if available.

      The current `Locale` retrieving strategy is:

      - If a current `UI` is available and a UI `Locale` is configured, the UI locale is returned.
      - If a `LocalizationContext` is available as a `Context` resource and it is localized, the `LocalizationContext` `Locale` is returned.
      - If a `I18NProvider` is available from the `VaadinService`, the first `Locale` from `I18NProvider.getProvidedLocales()` is returned, if available.
      Returns:
        Optional current `Locale`
      See Also:
        `LocalizationContext.getCurrent()`

    - #### getLocalization

          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.

      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.

      Parameters:
        `locale` - The `Locale` for which to obtain the message localization (not null)
        `localizable` - The `Localizable` which represents the message to localize (not null)
      Returns:
        The localized message, if available. If the given `localizable` provides a default message (`Localizable.getMessage()`) and a message localization is not available, the default message is returned
      See Also:
        `LocalizationContext.getCurrent()`

    - #### getLocalization

          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.

      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.

      Parameters:
        `locale` - The `Locale` for which to obtain the message localization (not null)
        `messageCode` - The message localization key (not null)
        `arguments` - Optional message localization arguments
      Returns:
        The localized message, if available
      See Also:
        `LocalizationContext.getCurrent()`

    - #### getLocalization

          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.

      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.

      Parameters:
        `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 code
        `messageCode` - The message localization key (not null)
        `arguments` - Optional message localization arguments
      Returns:
        The localized message, or the `defaultMessage` if not available
      See Also:
        `LocalizationContext.getCurrent()`

    - #### localize

          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.

      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.

      Parameters:
        `localizable` - The `Localizable` which represents the message to localize (not null)
      Returns:
        The localized message, if available. If the given `localizable` provides a default message (`Localizable.getMessage()`) and a message localization is not available, the default message is returned
      See Also:
        `getCurrentLocale()`

    - #### localize

          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.

      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.

      Parameters:
        `messageCode` - The message localization key (not null)
        `arguments` - Optional message localization arguments
      Returns:
        The localized message, if available
      See Also:
        `getCurrentLocale()`

    - #### localize

          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.

      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.

      Parameters:
        `defaultMessage` - The default message to use when a message localization is not available for the provided `Locale` and message code
        `messageCode` - The message localization key (not null)
        `arguments` - Optional message localization arguments
      Returns:
        The localized message, or the `defaultMessage` if not available
      See Also:
        `getCurrentLocale()`

Copyright © 2019 The Holon Platform. All rights reserved.