Package dev.satyrn.papermc.api.lang.v1
Class I18n
java.lang.Object
dev.satyrn.papermc.api.lang.v1.I18n
Provides internationalization support for a plugin.
- Since:
- 1.0.0
- Author:
- Isabel Maskrey
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic 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
Modifier and TypeFieldDescriptionstatic final @NotNull Locale
The default locale to use for translation. -
Constructor Summary
ModifierConstructorDescriptionInitializes a new I18n instance.protected
I18n
(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull ResourceBundle defaultBundle) Initializes a new I18n instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
disable()
Disables the internationalization handler.void
enable()
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
getResourceBundleForLocale
(@NotNull Locale locale) Gets a resource bundle for the current locale.final void
Sets the current locale of the internationalization handler.static String
Translates a resource key.protected final @NotNull String
Translates a string with the given formatting parts.
-
Field Details
-
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
Initializes a new I18n instance.- Parameters:
plugin
- The plugin instance.baseName
- The default resource bundle.- Since:
- 1.1.0
-
-
Method Details
-
getInstance
Gets the current I18n instance.- Returns:
- The current I18n instance.
- Since:
- 1.1.0
-
tr
Translates a resource key.- Parameters:
key
- The resource key.format
- The formatting for the message.- Returns:
- The translated key.
- Since:
- 1.0.0
-
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
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
-