Class Localizable

java.lang.Object
net.caseif.rosetta.Localizable

public class Localizable extends Object
Represents an object which has the potential to be localized in one of multiple languages and returned as a string.

In the event that a Localizable cannot be localized with the given parameters or in its parent LocaleManager's default locale, it will output its internal key instead.

Since:
1.0
  • Method Details

    • getParent

      public LocaleManager getParent()
      Gets the parent LocaleManager for this Localizable.
      Returns:
      The parent LocaleManager for this Localizable.
      Since:
      1.0
    • getKey

      public String getKey()
      Gets the key associated with this Localizable's message.
      Returns:
      The key associated with this Localizable's message
      Since:
      1.0
    • withReplacements

      public Localizable withReplacements(String... replacements)
      Sets the replacements for placeholder sequences in this Localizable.

      Placeholder sequences are defined as a percent symbol (%) followed by a number greater than or equal to 1. The first element of the replacement string array will replace any placeholder sequences matching %1, the second, sequences matching %2, and so on.

      Note: Mutating the contents of the array passed as a parameter after calling this method will not impact this Localizable.

      Parameters:
      replacements - The replacement strings to set for this Localizable
      Returns:
      This Localizable object, for chaining)
      Since:
      1.0
    • withReplacements

      public Localizable withReplacements(Localizable... replacements)
      Sets the replacements for placeholder sequences in this Localizable as Localizable objects. These objects will be localized appropriately when the parent Localizable (the object this method is invoked upon) is localized.

      Placeholder sequences are defined as a percent symbol (%) followed by a number greater than or equal to 1. The first element of the replacement string array will replace any placeholder sequences matching %1, the second, sequences matching %2, and so on.

      Note: Mutating the contents of the array passed as a parameter after calling this method will not impact this Localizable.

      Parameters:
      replacements - The replacement sequences to set for this Localizable
      Returns:
      This Localizable object, for chaining
      Since:
      1.1
    • withPrefix

      public Localizable withPrefix(String prefix)
      Sets the prefix to prepend to this Localizable when it is localized.
      Parameters:
      prefix - The prefix to prepend to this Localizable when it is localized.
      Returns:
      This Localizable object, for chaining
      Since:
      1.0
    • withSuffix

      public Localizable withSuffix(String suffix)
      Sets the suffix to append to this Localizable when it is localized.
      Parameters:
      suffix - The suffix to append to this Localizable when it is localized.
      Returns:
      This Localizable object, for chaining
      Since:
      1.0
    • localizeIn

      public String localizeIn(String locale, String... fallbacks)
      Localizes this Localizable in the given locale.

      It is unnecessary to include alternate dialects of a locale as fallbacks (e.g. en_GB as a fallback for en_US), as they are included by default by the library.

      Parameters:
      locale - The locale to localize this Localizable in
      fallbacks - Locales to fall back upon if this Localizable is not available in the player's locale (the parent LocaleManager's default locale will be used if all fallbacks are exhausted, and if this is unavailable, the value of getKey() will be used instead)
      Returns:
      A string representing the localized message, or this Localizable's internal key if no localizations are available
      Since:
      1.0
    • localize

      public String localize()
      Localizes this Localizable in the owning LocaleManager's default locale.
      Returns:
      The appropriate localization for this Localizable.
      Since:
      1.0
    • localizeFor

      public String localizeFor(org.bukkit.command.CommandSender sender)
      Localizes this Localizable for the given CommandSender. If the CommandSender is also a Player, the message will be localized in their respective locale. Otherwise, it will be localized in the parent LocaleManager's default locale.

      It is unnecessary to include alternate dialects of a locale as fallbacks (e.g. en_GB as a fallback for en_US), as they are included by default by the library.

      Parameters:
      sender - The CommandSender to localize this Localizable for
      Returns:
      A string representing the localized message, or this Localizable's internal key if no localizations are available
      Since:
      1.0
    • sendTo

      public void sendTo(org.bukkit.command.CommandSender sender)
      Sends this Localizable to the given CommandSender. If the CommandSender is also a Player, the message will be localized in their respective locale. Otherwise, it will be localized in the parent LocaleManager's default locale.

      It is unnecessary to include alternate dialects of a locale as fallbacks (e.g. en_GB as a fallback for en_US), as they are included by default by the library.

      Parameters:
      sender - The CommandSender to send this Localizable to
      Since:
      1.0
    • broadcast

      public void broadcast()
      Broadcasts this Localizable to all players on the server, applying the respective locale for each player.
      Since:
      1.0
    • broadcast

      public void broadcast(org.bukkit.World... worlds)
      Broadcasts this Localizable to all players in the given Worlds.
      Parameters:
      worlds - The Worlds to broadcast to
      Since:
      1.0