Class LocalizedString

java.lang.Object
com.lokalized.LocalizedString

@Immutable public final class LocalizedString extends Object
Represents a single localized string - its key, translated value, and any associated translation rules.

Normally instances are sourced from a file which contains all localized strings for a given locale.

Unicode letter, number, and mark membership in placeholder and expression identifiers follows the executing JDK's Pattern Unicode tables. For cross-JDK portability, author identifiers for the oldest JDK in the deployment fleet; [A-Za-z_][A-Za-z0-9_-]* is the portable ASCII subset.

Author:
Mark Allen
  • Method Details

    • toString

      Generates a bounded diagnostic String representation of this object.

      Deep, shared, cyclic, or oversized values may be abbreviated with reference, cycle, or truncation markers.

      Overrides:
      toString in class Object
      Returns:
      a string representation of this object, not null
    • equals

      public boolean equals(@Nullable Object other)
      Checks if this object is equal to another one.
      Overrides:
      equals in class Object
      Parameters:
      other - the object to check, null returns false
      Returns:
      true if this is equal to the other object, false otherwise
    • hashCode

      public int hashCode()
      A hash code for this object.
      Overrides:
      hashCode in class Object
      Returns:
      a suitable hash code
    • getKey

      Gets this string's translation key.
      Returns:
      this string's translation key, not null
    • getTranslation

      Gets this string's default translation, if available.
      Returns:
      this string's default translation, not null
    • getCommentary

      Gets this string's commentary (usage/translation notes).
      Returns:
      this string's commentary, not null
    • getPlaceholderDefinitions

      Gets the generated-placeholder definitions declared by this localized string.

      Current concrete types are LocalizedString.LanguageFormTranslation and LocalizedString.ExpressionTranslation. Consumers should inspect the definition type with instanceof before accessing subtype-specific state and handle unfamiliar future library-defined types defensively.

      Returns:
      generated-placeholder definitions keyed by placeholder name, not null
      Since:
      3.0.0
    • getAlternatives

      Gets alternative expression-driven translations for this string.

      In this context, the key for each alternative is a localization expression, not a translation key.

      For example, if bookCount == 0 you might want to say I haven't read any books instead of I read 0 books.

      Returns:
      alternative expression-driven translations for this string, not null