Interface LocalizationSourceRegistry
- All Superinterfaces:
LocalizationSource
A mutable localization source that can register localized strings.
-
Method Summary
Modifier and TypeMethodDescriptionstatic LocalizationSourceRegistryCreates a newLocalizationSourceRegistryinstance.Returns the default locale of this source.voidregister(String key, Locale locale, MessageFormat format) Registers a localized string.default voidregisterAll(Locale locale, String baseName, ClassLoader loader) Registers a resource bundle of localized strings via the classpath.default voidregisterAll(Locale locale, Path path) Registers a resource bundle of localized strings via a file system.default voidregisterAll(Locale locale, Map<String, MessageFormat> formats) Registers a map of localized strings.default voidregisterAll(Locale locale, ResourceBundle bundle) Registers a resource bundle of localized strings.default voidregisterAll(Locale locale, Set<String> keys, Function<String, MessageFormat> 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.common.localization.LocalizationSource
format, localize
-
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 toformats- the map of localized strings- Throws:
IllegalArgumentException- if a key is already registered
-
registerAll
Registers a resource bundle of localized strings.- Parameters:
locale- the locale to register the strings tobundle- the resource bundle to use- Throws:
IllegalArgumentException- if a key is already registered
-
registerAll
Registers a resource bundle of localized strings via the classpath.final Plugin plugin = ...; registry.registerAll(Locale.ENGLISH, "bundle", plugin.getClass().getClassLoader()); registry.registerAll(Locale.FRENCH, "bundle", plugin.getClass().getClassLoader());- Parameters:
locale- the locale to register the strings tobaseName- the base name of the resource bundleloader- the class loader to use- Throws:
IllegalArgumentException- if a key is already registered
-
registerAll
Registers a resource bundle of localized strings via a file system.final var english = Paths.get("bundle_en.properties"); registry.registerAll(Locale.ENGLISH, path); final var english = Paths.get("bundle_fr.properties"); registry.registerAll(Locale.FRENCH, path);- Parameters:
locale- the locale to register the strings topath- the path to the bundle file- Throws:
IllegalArgumentException- if a key is already registeredIOException
-
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 toformat- 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.
-