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.
  • Method Details

    • of

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

      Example: I18nText.of("{{1}} {{2}} ran across the {{3}}", "500", "elephants", "savanna"); produces 500 elephants ran across the savanna

      If you need to translate the tokens also, see of(String,IString...).

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

      public static I18nText of(@Nonnull String text, @Nonnull IString... tokens)
      Create a translatable string where the tokens are translatable individually.

      Example: I18nText.of("{{1}} {{2}} ran across the {{3}}", Text.of("500"), I18nText.of("elephants"), I18nText.of("savanna"); produces 500 elephants ran across the savanna, where everything except 500 will be translated.

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

      public static I18nText of(@Nonnull String text)
      Parameters:
      text - to appear as a translated string
      Returns:
      Object representing translatable 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. Either List<String> or List<IString>
    • 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