Class FluavaLocalizer

java.lang.Object
com.github.kaktushose.jda.commands.i18n.FluavaLocalizer
All Implemented Interfaces:
Implementation.ExtensionProvidable, Localizer

public final class FluavaLocalizer extends Object implements Localizer

The default variant of Localizer, which implements it with help of the amazing java implementation of project fluent.

Due to limitations set by fluent, dots contained in keys will be replaced by -. So my.key becomes my-key. Note that all localization keys generated by jda are also effected by this.

Implementation Note:
This class caches all loaded bundles.
  • Constructor Details

    • FluavaLocalizer

      public FluavaLocalizer(dev.goldmensch.fluava.Fluava fluava)
      Parameters:
      fluava - the Fluava instance to use
  • Method Details

    • localize

      public Optional<String> localize(Locale locale, String bundle, String key, Map<String,Object> arguments)

      This method localizes a given key for a specific bundle and locale. If no message is found for this combination of locale, bundle and key or an error occurred Optional.empty() should be returned. For further information regarding functionality, you can take a look at the documentation of:

      • Fluava.loadBundle(String) for bundle loading
      • Bundle.apply(java.util.Locale, java.lang.String, java.util.Map) for localization of a given key
      Specified by:
      localize in interface Localizer
      Parameters:
      locale - the asked for locale
      bundle - the bundle to search the key in
      key - the key to be searched for. Note that all dots will be replaced by -.
      arguments - values for placeholder in the message
      Returns:
      the localized message or Optional.empty() if no key is found/an error occurred
    • localizeMessage

      public Optional<String> localizeMessage(Locale locale, String content, Map<String,Object> arguments)
      This method localizes the given message content for the specific locale and arguments. The purpose of this method is to support replacing placeholders in text fields of components, embeds and modals that aren't retrieved from Localizer.localize(Locale, String, String, Map)
      Specified by:
      localizeMessage in interface Localizer
      Parameters:
      locale - the asked for locale
      content - the content of the message to be localized, the content should be treated as if it's received from some localization file
      arguments - values for placeholder in the message
      Returns:
      the localized message or Optional.empty() if an error occurred