Package dev.orne.i18n

Interface I18nString

All Superinterfaces:
Serializable
All Known Implementing Classes:
I18nFixedString, I18nResourcesString, I18nStringMap

@API(status=STABLE, since="0.1") public interface I18nString extends Serializable
Interface for I18N texts.
Since:
0.1
Version:
1.0, 2021-01
Author:
(w) Iker Hernaez
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull I18nStringMap
    Returns this instance represented as an I18nStringMap instance.
    static @NotNull I18nFixedString
    fixed(String text)
    Returns a I18nFixedString instance for the specified text.
    fromResources(@NotNull String defaultMessage)
    Creates a new I18nResourcesString builder with the specified default text.
    @NotNull String
    get()
    Returns the text for the current language.
    @NotNull String
    get(@NotNull String language)
    Returns the text for the specified language, or the default text if no translation is available.
    @NotNull String
    get(@NotNull Locale locale)
    Returns the text for language of the specified locale, or the default text if no translation is available.
    boolean
    Returns true if the specified I18nString is equivalent to this instance.
    static @NotNull I18nStringMap
    mapped(@NotNull String defaultText)
    Creates a new I18nStringMap instance with specified default text and no translations.
  • Method Details

    • fixed

      @NotNull static @NotNull I18nFixedString fixed(String text)
      Returns a I18nFixedString instance for the specified text.

      Will return null if text is null.

      Parameters:
      text - The fixed text for all languages
      Returns:
      A instance with the specified text, or null if text is null
      See Also:
    • mapped

      @NotNull static @NotNull I18nStringMap mapped(@NotNull @NotNull String defaultText)
      Creates a new I18nStringMap instance with specified default text and no translations.
      Parameters:
      defaultText - The default text
      Returns:
      The created instance
    • fromResources

      @NotNull static I18nResourcesString.Builder fromResources(@NotNull @NotNull String defaultMessage)
      Creates a new I18nResourcesString builder with the specified default text.
      Parameters:
      defaultMessage - The default text
      Returns:
      The new I18nResourcesString builder
      See Also:
    • get

      @NotNull @NotNull String get()
      Returns the text for the current language.
      Returns:
      The text for the current language
    • get

      @NotNull @NotNull String get(@NotNull @NotNull String language)
      Returns the text for the specified language, or the default text if no translation is available.
      Parameters:
      language - The language of the requested text
      Returns:
      The text for the specified language
    • get

      @NotNull @NotNull String get(@NotNull @NotNull Locale locale)
      Returns the text for language of the specified locale, or the default text if no translation is available.
      Parameters:
      locale - The language of the requested text
      Returns:
      The text for the specified language
    • isEquivalent

      @API(status=EXPERIMENTAL, since="0.1") boolean isEquivalent(I18nString other)
      Returns true if the specified I18nString is equivalent to this instance.
      1. If other is null returns false.
      2. If other is of the same type calls equals().
      3. Otherwise checks that the translations for current language of both instances are equal.
      Parameters:
      other - The instance to compare against
      Returns:
      If both instances are equivalent
    • asMap

      @NotNull @NotNull I18nStringMap asMap()
      Returns this instance represented as an I18nStringMap instance.
      Returns:
      This instance represented as an I18nStringMap instance