Interface IDefaultMessageLocalizerBuilder
public interface IDefaultMessageLocalizerBuilder
A builder for
message localizers with common options. Allows setting the message loader,
the message formatter, and the fallback message factory separately.- Since:
- 8.5.0
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates a new default message localizer with the configured options.buildBound(Locale locale) Creates a new bound default message localizer with the configured options, bound to the given locale.fallbackLocale(Locale fallbackLocale) Sets the fallback locale to use when no message is available for the requested locale.fallbackMessageFactory(ISerializableFunction<? super String, ? extends String> fallbackMessageFactory) Sets the fallback message factory.messageFormatter(ISerializableBiFunction<? super String, ? super Object[], ? extends String> messageFormatter) Sets the message formatter to use to format messages with parameters.messageLoader(ISerializableBiFunction<? super Locale, ? super String, ? extends String> messageLoader) Sets a custom message loader.resourceBundleMessageLoader(ISerializableFunction<? super Locale, ? extends ResourceBundle> resourceBundleFactory) Sets a message loader that retrieves message from the message bundle obtained from the given factory.resourceBundleMessageLoader(String baseName, ClassLoader classLoader) Sets a message loader that retrieves message from the message bundle retrieved from the given base name.
-
Method Details
-
build
IMessageLocalizer build()Creates a new default message localizer with the configured options.- Returns:
- The new message localizer.
-
buildBound
Creates a new bound default message localizer with the configured options, bound to the given locale.- Parameters:
locale- The locale to bind the message localizer to. Defaults toENGLISH.- Returns:
- The new bound message localizer.
-
fallbackLocale
Sets the fallback locale to use when no message is available for the requested locale. Defaults toENGLISH. Set this to null to disable locale fallback.- Parameters:
fallbackLocale- The fallback locale.- Returns:
- This builder instance for chaining method calls.
-
fallbackMessageFactory
@CanIgnoreReturnValue IDefaultMessageLocalizerBuilder fallbackMessageFactory(ISerializableFunction<? super String, ? extends String> fallbackMessageFactory) Sets the fallback message factory. The factory is given the message key and must return a fallback message. It may return null to indicate no fallback is available. Defaults to a factory that returns "???[messageKey]???".- Parameters:
fallbackMessageFactory- The fallback message factory.- Returns:
- This builder instance for chaining method calls.
-
messageFormatter
@CanIgnoreReturnValue IDefaultMessageLocalizerBuilder messageFormatter(ISerializableBiFunction<? super String, ? super Object[], ? extends String> messageFormatter) Sets the message formatter to use to format messages with parameters. The formatter is given the message pattern to format, and the parameters. Defaults toMessageFormat.format(String, Object...).- Parameters:
messageFormatter- The message formatter.- Returns:
- This builder instance for chaining method calls.
-
messageLoader
@CanIgnoreReturnValue IDefaultMessageLocalizerBuilder messageLoader(ISerializableBiFunction<? super Locale, ? super String, ? extends String> messageLoader) Sets a custom message loader. The loader is given the locale and the message key and must return the corresponding message. When no message is available for the given locale and key, the loader must return null. Defaults to a no-op loader that always returns null.- Parameters:
messageLoader- The message loader.- Returns:
- This builder instance for chaining method calls.
- See Also:
-
resourceBundleMessageLoader
@CanIgnoreReturnValue IDefaultMessageLocalizerBuilder resourceBundleMessageLoader(String baseName, ClassLoader classLoader) Sets a message loader that retrieves message from the message bundle retrieved from the given base name. Defaults to a no-op loader that always returns null.- Parameters:
baseName- The base name of the resource bundle, a fully qualified class name.classLoader- The class loader to use to load the resource bundles.- Returns:
- This builder instance for chaining method calls.
- See Also:
-
resourceBundleMessageLoader
@CanIgnoreReturnValue IDefaultMessageLocalizerBuilder resourceBundleMessageLoader(ISerializableFunction<? super Locale, ? extends ResourceBundle> resourceBundleFactory) Sets a message loader that retrieves message from the message bundle obtained from the given factory. Defaults to a no-op loader that always returns null.- Parameters:
resourceBundleFactory- The factory that provides the resource bundle for a given locale.- Returns:
- This builder instance for chaining method calls.
- See Also:
-