Class FluavaLocalizer
- All Implemented Interfaces:
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. Also, a sub instance of the passed Fluava instance
is created with
FluavaBuilder.FunctionConfig.fallbackToString(boolean)set totrue.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThis method localizes a given key for a specific bundle and locale.This method localizes a given key (coming from JDA'sLocalizationFunction) for a specific bundle and locale.
-
Constructor Details
-
FluavaLocalizer
public FluavaLocalizer(dev.goldmensch.fluava.Fluava parent) - Parameters:
parent- theFluavainstance to use
-
-
Method Details
-
localize
public Optional<String> localize(Locale locale, String bundle, String key, Map<String, @Nullable 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 loadingBundle.apply(java.util.Locale, java.lang.String, java.util.Map)for localization of a given key
- Specified by:
localizein interfaceLocalizer- Parameters:
locale- the asked for localebundle- the bundle to search the key inkey- 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
-
localizeJDA
public Optional<String> localizeJDA(Locale locale, String bundle, String key, Map<String, @Nullable Object> arguments) This method localizes a given key (coming from JDA's
LocalizationFunction) for a specific bundle and locale. If no message is found for this combination of locale, bundle and key or an error occurredOptional.empty()should be returned.The difference to
Localizer.localize(Locale, String, String, Map)is, that this method is only used inside our implementation ofLocalizationFunction, thus the keys always follow the JDA format (parts are separated by a dot.).For example, project fluent (
Fluava) disallows.as a "normal" separator in localization keys, therefore we have to replace all.with-and then pass it to theLocalizer.localize(Locale, String, String, Map)method.For further information regarding functionality, you can take a look at the documentation of:
Fluava.loadBundle(String)for bundle loadingBundle.apply(java.util.Locale, java.lang.String, java.util.Map)for localization of a given key
- Specified by:
localizeJDAin interfaceLocalizer- Parameters:
locale- the asked for localebundle- the bundle to search the key inkey- 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
-