Interface BundleTranslationSource
- All Superinterfaces:
TranslationSource
A translation source that can register strings from resource bundles, files and others.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BundleTranslationSourceCreates a newLocalizationSourceRegistryinstance.Returns the default locale of this source.voidregister(String key, Locale locale, Translation translation) Registers a localized string.default voidregisterAll(TranslationBundle bundle) default voidregisterAll(Locale locale, Map<String, Translation> translations) Registers a map of localized strings.default voidregisterAll(Locale locale, Set<String> keys, Function<String, Translation> function) Registers a set of localized strings by using a mapping function to obtain each string.booleanregistered(String key) Checks if a key is already registered, for any locale.booleanregistered(String key, Locale locale) Checks if a key is already registered for a specific locale.voidunregister(String key) Unregisters a localized string.Methods inherited from interface com.xpdustry.distributor.api.translation.TranslationSource
getTranslation, getTranslationOrDefault, getTranslationOrMissing
-
Method Details
-
create
Creates a newLocalizationSourceRegistryinstance.- Parameters:
defaultLocale- the default locale of the localization source- Returns:
- a new
LocalizationSourceRegistryinstance
-
registerAll
Registers a map of localized strings.final var strings = new HashMap<String, MessageFormat>(); strings.put("example.hello", new MessageFormat("Hello {0}!", Locale.ENGLISH)); strings.put("example.goodbye", new MessageFormat("Goodbye {0}!", Locale.ENGLISH)); registry.registerAll(Locale.ENGLISH, strings);- Parameters:
locale- the locale to register the strings totranslations- the map of localized strings- Throws:
IllegalArgumentException- if a key is already registered
-
registerAll
-
registerAll
Registers a set of localized strings by using a mapping function to obtain each string.- Parameters:
locale- the locale to register the strings tokeys- the set of keys to registerfunction- the mapping function- Throws:
IllegalArgumentException- if the key is already registered
-
register
Registers a localized string.- Parameters:
key- the key of the stringlocale- the locale to register the string totranslation- the localized string- Throws:
IllegalArgumentException- if the key is already registered
-
registered
Checks if a key is already registered, for any locale.- Parameters:
key- the key to check- Returns:
trueif the key is already registered,falseotherwise
-
registered
Checks if a key is already registered for a specific locale.- Parameters:
key- the key to checklocale- the locale to check- Returns:
trueif the key is already registered for the specific locale,falseotherwise
-
unregister
Unregisters a localized string.- Parameters:
key- the key of the string
-
getDefaultLocale
Locale getDefaultLocale()Returns the default locale of this source.
-