Class ResourceBundleLocalizationFunction
java.lang.Object
net.dv8tion.jda.api.interactions.commands.localization.ResourceBundleLocalizationFunction
- All Implemented Interfaces:
LocalizationFunction
A default implementation for
LocalizationFunction
This implementation supports Java's ResourceBundle
to be used as a localization source
You can look at a complete localization example here
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder forResourceBundleLocalizationFunction
Use the factory methods inResourceBundleLocalizationFunction
to create instances of this builder -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the localization mappings of the specified localization keyempty()
Creates an emptyResourceBundleLocalizationFunction
builder.fromBundle
(ResourceBundle resourceBundle, DiscordLocale locale) Creates an emptyResourceBundleLocalizationFunction
builder and adds the provided bundle and locale.fromBundles
(String baseName, DiscordLocale... locales) Creates aResourceBundleLocalizationFunction
builder with the provided bundles.
-
Method Details
-
apply
Description copied from interface:LocalizationFunction
Retrieves the localization mappings of the specified localization key- Specified by:
apply
in interfaceLocalizationFunction
- Parameters:
localizationKey
- The localization key to get the translations from- Returns:
- Never-null map of discord locales to their localized strings
-
fromBundle
@Nonnull public static ResourceBundleLocalizationFunction.Builder fromBundle(@Nonnull ResourceBundle resourceBundle, @Nonnull DiscordLocale locale) Creates an emptyResourceBundleLocalizationFunction
builder and adds the provided bundle and locale.
This is the same as usingResourceBundleLocalizationFunction.empty().addBundle(resourceBundle, locale)
Example usage:
This creates a LocalizationFunction from a French ResourceBundle (MyCommands_fr.properties)final LocalizationFunction localizationFunction = ResourceBundleLocalizationFunction .fromBundle(ResourceBundle.getBundle("MyCommands", Locale.FRENCH), DiscordLocale.FRENCH) .build();
- Parameters:
resourceBundle
- The resource bundle to get the localized strings fromlocale
- The locale of the resources- Returns:
- The new builder
- Throws:
IllegalArgumentException
-- If the resource bundle is null
- If the locale is null
- If the locale is
DiscordLocale.UNKNOWN
-
fromBundles
@Nonnull public static ResourceBundleLocalizationFunction.Builder fromBundles(@Nonnull String baseName, @Nonnull DiscordLocale... locales) Creates aResourceBundleLocalizationFunction
builder with the provided bundles.
This will insert the resource bundles with the specified name, with each specified locale.
This is the same as usingResourceBundleLocalizationFunction.empty().addBundles(baseName, locales)
Example usage:
This creates a LocalizationFunction from 2 resource bundles, one in Spanish (MyCommands_es_ES.properties) and one in French (MyCommands_fr.properties)final LocalizationFunction localizationFunction = ResourceBundleLocalizationFunction .fromBundles("MyCommands", DiscordLocale.SPANISH, DiscordLocale.FRENCH) .build();
- Parameters:
baseName
- The base name of the resource bundle, for example, the base name of"MyBundle_fr_FR.properties"
would be"MyBundle"
locales
- The locales to get from the resource bundle- Returns:
- The new builder
- Throws:
IllegalArgumentException
-- If the base name is null
- If the locales or one of the locale is null
- If one of the locale is
DiscordLocale.UNKNOWN
-
empty
Creates an emptyResourceBundleLocalizationFunction
builder.- Returns:
- The empty builder
-