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
Nested ClassesModifier and TypeClassDescriptionstatic final classCustom class loader which loads locale bundles from the plugin data folder.static classGathers a UTF-8 *.lang file into a resource bundle. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NotNull LocaleThe default locale to use for translation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionInitializes a new I18n instance.protectedI18n(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull ResourceBundle defaultBundle) Initializes a new I18n instance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddisable()Disables the internationalization handler.voidenable()Enables the internationalization handler.@NotNull LocaleGets the current locale.static @Nullable I18nGets the current I18n instance.@NotNull org.bukkit.plugin.PluginGets the plugin instance.protected @NotNull ResourceBundlegetResourceBundleForLocale(@NotNull Locale locale) Gets a resource bundle for the current locale.final voidSets the current locale of the internationalization handler.static StringTranslates a resource key.protected final @NotNull StringTranslates 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
-