Interface BundleTranslationSource
- All Superinterfaces:
TranslationSource
A translation source that can register translation from resource bundles and other sources.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Unregisters all translations.static BundleTranslationSourceCreates a newBundleTranslationSourceinstance.Returns the default locale of this source.getKeys()Returns the keys of all registered translations.Returns the keys of all registered translations for a specific locale.voidregister(String key, Locale locale, Translation translation) Registers a translation.default voidregisterAll(Collection<ResourceBundle> bundles) Registers the entries of the given resource bundles as text translations.default voidregisterAll(Collection<ResourceBundle> bundles, BiFunction<ResourceBundle, String, Translation> extractor) Registers the entries of the given resource bundles.default voidregisterAll(Locale locale, Map<String, Translation> translations) Registers a map of translations.default voidregisterAll(Locale locale, Set<String> keys, Function<String, Translation> mapper) Registers a set of translations by using a mapper function to obtain each translation.default voidregisterAll(ResourceBundle bundle) Registers the entries of the given resource bundle as text translations.default voidregisterAll(ResourceBundle bundle, BiFunction<ResourceBundle, String, Translation> extractor) Registers the entries of the given resource bundle.booleanregistered(String key) Checks if a key is registered for any locale.booleanregistered(String key, Locale locale) Checks if a key is registered for a specific locale.voidunregister(String key) Unregisters a key.voidunregister(String key, Locale locale) Unregisters a key for a specific locale.Methods inherited from interface com.xpdustry.distributor.api.translation.TranslationSource
getTranslation, getTranslationOrDefault, getTranslationOrMissing
-
Method Details
-
create
Creates a newBundleTranslationSourceinstance.- Parameters:
defaultLocale- the default locale of the translation source- Returns:
- a new
BundleTranslationSourceinstance
-
registerAll
Registers a map of translations.- Parameters:
locale- the locale of the translationstranslations- the map- Throws:
IllegalArgumentException- if a key is already registered
-
registerAll
Registers the entries of the given resource bundle as text translations.- Parameters:
bundle- the resource bundle
-
registerAll
default void registerAll(ResourceBundle bundle, BiFunction<ResourceBundle, String, Translation> extractor) Registers the entries of the given resource bundle.- Parameters:
bundle- the resource bundleextractor- the function to extractTranslation
-
registerAll
Registers the entries of the given resource bundles as text translations.- Parameters:
bundles- the collection of resource bundles
-
registerAll
default void registerAll(Collection<ResourceBundle> bundles, BiFunction<ResourceBundle, String, Translation> extractor) Registers the entries of the given resource bundles.- Parameters:
bundles- the collection of resource bundlesextractor- the function to extractTranslation
-
registerAll
Registers a set of translations by using a mapper function to obtain each translation.- Parameters:
locale- the locale of the translationskeys- the set of keys to registermapper- the mapper function to obtain the translation- Throws:
IllegalArgumentException- if the key is already registered
-
register
Registers a translation.- Parameters:
key- the key of the translationlocale- the locale of the translationtranslation- the translation- Throws:
IllegalArgumentException- if the key is already registered
-
registered
Checks if a key is registered for any locale.- Parameters:
key- the key of- Returns:
trueif the key is registered,falseotherwise
-
registered
Checks if a key is registered for a specific locale.- Parameters:
key- the keylocale- the locale to check- Returns:
trueif the key is registered for the specific locale,falseotherwise
-
unregister
Unregisters a key.- Parameters:
key- the key of the string
-
unregister
Unregisters a key for a specific locale.- Parameters:
key- the keylocale- the locale
-
clear
void clear()Unregisters all translations. -
getDefaultLocale
Locale getDefaultLocale()Returns the default locale of this source. -
getKeys
Collection<String> getKeys()Returns the keys of all registered translations. -
getKeys
Returns the keys of all registered translations for a specific locale.- Parameters:
locale- the locale
-