Class I18nSpringResources

java.lang.Object
dev.orne.i18n.spring.I18nSpringResources
All Implemented Interfaces:
I18nResources

@API(status=STABLE, since="0.1") public class I18nSpringResources extends Object implements I18nResources
Implementation of I18nResources based on Spring MessageSource.
Since:
0.1
Version:
1.0, 2021-01
Author:
(w) Iker Hernaez
See Also:
  • Constructor Details

    • I18nSpringResources

      public I18nSpringResources(@NotNull @NotNull org.springframework.context.MessageSource source)
      Creates a new instance.
      Parameters:
      source - The I18N messages source
  • Method Details

    • getSource

      public org.springframework.context.MessageSource getSource()
      Returns the I18N messages source.
      Returns:
      The I18N messages source
    • getMessage

      @NotNull public @NotNull String getMessage(@NotNull @NotNull String defaultMessage, @NotNull @NotNull String code, @NotNull @NotNull Locale locale, Object... params)
      Retrieves the I18N message for the specified message code and locale. If the message code is not defined in this I18N resources the specified default message is used. The message is formatted with the provided parameters.
      Specified by:
      getMessage in interface I18nResources
      Parameters:
      defaultMessage - The default message format
      code - The message code
      locale - The locale to retrieve the message for
      params - The message parameters
      Returns:
      The formatted message in the specified locale
    • getMessage

      @NotNull public @NotNull String getMessage(@NotNull @NotNull String defaultMessage, @NotNull @NotNull String[] codes, @NotNull @NotNull Locale locale, Object... params)
      Retrieves the I18N message for the specified locale of the first message code efined in this I18N resources of specified message codes. If no message code is defined in this I18N resources the specified default message is used. The message is formatted with the provided parameters.
      Specified by:
      getMessage in interface I18nResources
      Parameters:
      defaultMessage - The default message format
      codes - The message codes, in order of preference
      locale - The locale to retrieve the message for
      params - The message parameters
      Returns:
      The formatted message in the specified locale