Interface Translator


public interface Translator
Represents a translator. A translator allows localizing messages, adding bundles, registering custom locales, and changing the default locale.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(@NotNull ResourceBundle resourceBundle)
    Registers the given resource bundle
    void
    add(@NotNull LocaleReader reader)
    Adds the given locale reader to this translator.
    void
    addResourceBundle(@NotNull String resourceBundle)
    Adds the given resource bundle.
    void
    addResourceBundle(@NotNull String resourceBundle, @NotNull Locale... locales)
    Adds the given resource bundle.
    static @NotNull Translator
    Creates a new Translator
    @NotNull String
    get(@NotNull String key)
    Returns the message that corresponds to the given key, using the current getLocale().
    @NotNull String
    get(@NotNull String key, @NotNull Locale locale)
    Returns the message that corresponds to the given key, using the given locale.
    @NotNull Locale
    Gets the current, default locale used by this translator
    void
    setLocale(@NotNull Locale locale)
    Sets the locale of this translator.
  • Method Details

    • create

      @NotNull static @NotNull Translator create()
      Creates a new Translator
      Returns:
      The newly created translator
    • get

      @NotNull @NotNull String get(@NotNull @NotNull String key)
      Returns the message that corresponds to the given key, using the current getLocale(). If no such message is found, the key will be returned.
      Parameters:
      key - Message key to fetch with
      Returns:
      The translated message, or the key if not found.
    • get

      @NotNull @NotNull String get(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
      Returns the message that corresponds to the given key, using the given locale. If no such message is found, the key will be returned.
      Parameters:
      key - Message key to fetch with
      locale - Locale to get with
      Returns:
      The translated message, or the key if not found.
    • add

      void add(@NotNull @NotNull LocaleReader reader)
      Adds the given locale reader to this translator.
      Parameters:
      reader - The locale reader to add
    • add

      void add(@NotNull @NotNull ResourceBundle resourceBundle)
      Registers the given resource bundle
      Parameters:
      resourceBundle - Resource bundle to register
    • addResourceBundle

      void addResourceBundle(@NotNull @NotNull String resourceBundle, @NotNull @NotNull Locale... locales)
      Adds the given resource bundle. This will only register for the given Locales.

      For example, if you have the following files:

      • foo_en_US.properties
      • foo_fr.properties
      • foo_de.properties
      The resource bundle will be "foo", and locales will be each Locales.ENGLISH, Locales.FRENCH and Locales.GERMAN.
      Parameters:
      resourceBundle - Resource bundle to register
      locales - Locales to register for
    • addResourceBundle

      void addResourceBundle(@NotNull @NotNull String resourceBundle)
      Adds the given resource bundle. This will automatically check for all locales in Locales.

      For example, if you have the following files:

      • foo_en_US.properties
      • foo_fr.properties
      • foo_de.properties
      The resource bundle will be "foo", and all bundles will be parsed automatically.
      Parameters:
      resourceBundle - Resource bundle to register
    • getLocale

      @NotNull @NotNull Locale getLocale()
      Gets the current, default locale used by this translator
      Returns:
      The default locale
    • setLocale

      void setLocale(@NotNull @NotNull Locale locale)
      Sets the locale of this translator.
      Parameters:
      locale - The locale of this translator