Class I18nText

java.lang.Object
com.persequor.extension.frontend.I18nText
All Implemented Interfaces:
IString

public class I18nText extends Object implements IString
IString implementation for translatable text. For non-translatable text use Text.
  • Field Details

    • NULL_TEXT

      public static final I18nText NULL_TEXT
  • Method Details

    • toMap

      public static Map<String,IString> toMap(Collection<String> keys)
      Parameters:
      keys - collection of Strings to be used as keys of the map
      Returns:
      a Map with translatable texts as the values
    • of

      public static I18nText of(String text, @Nonnull Object... tokens)
      In order to support translation of variable text, add the variable part of your text as tokens.

      Example: I18nText.of("{{1}} {{2}} ran across the {{3}}", "500", "elephants", "savanna"); produces 500 elephants ran across the savanna
      Note: If you want the tokens to be translatable, pass them as I18nText.

      Parameters:
      text - Text to be shown
      tokens - tokens to replace into the text/translated text
      Returns:
      Object representing translatable text
    • join

      public static Text join(@Nonnull String delimiter, @Nonnull String... tokens)
      Example: Text.join(" ", "500", "elephants", "ran", "across", "the", "savanna"); produces 500 elephants ran across the savanna. All the tokens will be translatable
      Note: If you want the tokens to not be translatable, use Text.join(String, Object...).
      Parameters:
      delimiter - Delimiter to use between tokens
      tokens - tokens to join
      Returns:
      Object representing text
    • join

      public static Text join(@Nonnull String delimiter, @Nonnull List<String> tokens)
      Example: Text.join(" ", "500", "elephants", "ran", "across", "the", "savanna"); produces 500 elephants ran across the savanna. All the tokens will be translatable
      Note: If you want the tokens to not be translatable, use Text.join(String, Object...).
      Parameters:
      delimiter - Delimiter to use between tokens
      tokens - tokens to join
      Returns:
      Object representing text
    • getText

      @Nonnull public String getText()
      Specified by:
      getText in interface IString
      Returns:
      the original base text without any translation or token replacement
    • getTokens

      @Nonnull public List<Object> getTokens()
      Specified by:
      getTokens in interface IString
      Returns:
      the tokens to replace into the text/translated text
    • getType

      @Nonnull public StringType getType()
      Specified by:
      getType in interface IString
      Returns:
      whether this IString is translatable or not
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object