Package com.lokalized

Class DefaultStrings

java.lang.Object
com.lokalized.DefaultStrings
All Implemented Interfaces:
Strings

@ThreadSafe public class DefaultStrings extends Object implements Strings
Default implementation of a localized string provider.

It is recommended to use a single instance of this class across your entire application.

In multi-tenant systems like a web application where each user might have a different locale, your localeSupplier might return the locale specified by current request.

Author:
Mark Allen
  • Method Details

    • get

      @Nonnull public String get(@Nonnull String key)
      Description copied from interface: Strings
      Gets a localized string for the given key.

      If no localized string is available, the key is returned.

      Specified by:
      get in interface Strings
      Parameters:
      key - the localization key, not null
      Returns:
      a localized string for the key, not null
    • get

      @Nonnull public String get(@Nonnull String key, @Nullable Locale locale)
      Description copied from interface: Strings
      Gets a localized string for the given key.

      If no localized string is available, the key is returned.

      Specified by:
      get in interface Strings
      Parameters:
      key - the localization key, not null
      locale - the preferred locale for the string, may be null
      Returns:
      a localized string for the key, not null
    • get

      @Nonnull public String get(@Nonnull String key, @Nullable Map<String,Object> placeholders)
      Description copied from interface: Strings
      Gets a localized string for the given key.

      If no localized string is available, the key is returned.

      Specified by:
      get in interface Strings
      Parameters:
      key - the localization key, not null
      placeholders - the placeholders to insert into the string, may be null
      Returns:
      a localized string for the key, not null
    • get

      @Nonnull public String get(@Nonnull String key, @Nullable Map<String,Object> placeholders, @Nullable Locale locale)
      Description copied from interface: Strings
      Gets a localized string for the given key.

      If no localized string is available, the key is returned.

      Specified by:
      get in interface Strings
      Parameters:
      key - the localization key, not null
      placeholders - the placeholders to insert into the string, may be null
      locale - the preferred locale for the string, may be null
      Returns:
      a localized string for the key, not null
    • getFallbackLanguageCode

      @Nonnull public String getFallbackLanguageCode()
      Gets the fallback language code.
      Returns:
      the fallback language code, not null
    • getLocalizedStringsByLocale

      Gets the set of localized strings for each locale.
      Returns:
      the set of localized strings for each locale, not null
    • getFailureMode

      Gets the strategy for handling string lookup failures.
      Returns:
      the strategy for handling string lookup failures, not null