Class I18n

java.lang.Object
dev.satyrn.papermc.api.lang.v1.I18n

public class I18n extends Object
Provides internationalization support for a plugin.
Since:
1.0.0
Author:
Isabel Maskrey
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Custom class loader which loads locale bundles from the plugin data folder.
    static class 
    Gathers a UTF-8 *.lang file into a resource bundle.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final @NotNull Locale
    The default locale to use for translation.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    I18n(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull String baseName)
    Initializes a new I18n instance.
    protected
    I18n(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull ResourceBundle defaultBundle)
    Initializes a new I18n instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disables the internationalization handler.
    void
    Enables the internationalization handler.
    @NotNull Locale
    Gets the current locale.
    static @Nullable I18n
    Gets the current I18n instance.
    @NotNull org.bukkit.plugin.Plugin
    Gets the plugin instance.
    protected @NotNull ResourceBundle
    Gets a resource bundle for the current locale.
    final void
    setLocale(@Nullable String locale)
    Sets the current locale of the internationalization handler.
    static String
    tr(@NotNull String key, @NotNull Object... format)
    Translates a resource key.
    protected final @NotNull String
    translate(@NotNull String key, @NotNull Object... format)
    Translates a string with the given formatting parts.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_LOCALE

      @NotNull public static final @NotNull Locale DEFAULT_LOCALE
      The default locale to use for translation.
      Since:
      1.1.0
  • Constructor Details

    • I18n

      protected I18n(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull ResourceBundle defaultBundle)
      Initializes a new I18n instance.
      Parameters:
      plugin - The plugin instance.
      defaultBundle - The default resource bundle.
      Since:
      1.1.0
    • I18n

      public I18n(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull String baseName)
      Initializes a new I18n instance.
      Parameters:
      plugin - The plugin instance.
      baseName - The default resource bundle.
      Since:
      1.1.0
  • Method Details

    • getInstance

      @Nullable public static @Nullable I18n getInstance()
      Gets the current I18n instance.
      Returns:
      The current I18n instance.
      Since:
      1.1.0
    • tr

      public static String tr(@NotNull @NotNull String key, @NotNull @NotNull Object... format)
      Translates a resource key.
      Parameters:
      key - The resource key.
      format - The formatting for the message.
      Returns:
      The translated key.
      Since:
      1.0.0
    • getCurrentLocale

      @NotNull public @NotNull Locale getCurrentLocale()
      Gets the current locale.
      Returns:
      The current locale.
      Since:
      1.2.0
    • getPlugin

      @NotNull public @NotNull org.bukkit.plugin.Plugin getPlugin()
      Gets the plugin instance.
      Returns:
      The plugin instance.
      Since:
      1.1.0
    • translate

      @NotNull protected final @NotNull String translate(@NotNull @NotNull String key, @NotNull @NotNull Object... format)
      Translates a string with the given formatting parts.
      Parameters:
      key - The key to translate.
      format - The message format parts
      Returns:
      The translated key.
      Since:
      1.1.0
    • setLocale

      public final void setLocale(@Nullable @Nullable String locale)
      Sets the current locale of the internationalization handler.
      Parameters:
      locale - The locale string.
      Since:
      1.1.0
    • getResourceBundleForLocale

      @NotNull protected @NotNull ResourceBundle getResourceBundleForLocale(@NotNull @NotNull Locale locale)
      Gets a resource bundle for the current locale.
      Parameters:
      locale - The current locale.
      Returns:
      The new resource bundle.
      Since:
      1.0.0
    • enable

      public void enable()
      Enables the internationalization handler.
      Since:
      1.1.0
    • disable

      public void disable()
      Disables the internationalization handler.
      Since:
      1.1.0