Package dev.orne.i18n.context
Class I18nBundleResources
java.lang.Object
dev.orne.i18n.context.I18nBundleResources
- All Implemented Interfaces:
I18nResources
@API(status=STABLE,
since="0.1")
public class I18nBundleResources
extends Object
implements I18nResources
Implementation of
I18nResources
based on ResourceBundle
.- Since:
- 0.1
- Version:
- 1.0, 2021-01
- Author:
- (w) Iker Hernaez
- See Also:
-
Constructor Summary
ConstructorDescriptionI18nBundleResources
(@NotNull String baseName) Creates a new instance for the specified bundle. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull I18nResources
forBasename
(@NotNull String baseName) Returns a non null I18N resources for the specified bundle base name.protected @NotNull ResourceBundle
Returns the I18N resources bundle for the current locale.protected @NotNull ResourceBundle
Returns the I18N resources bundle for the specified locale.@NotNull String
getMessage
(@NotNull String defaultMessage, @NotNull String[] codes, Locale locale, Object... params) Retrieves the I18N message for the specified locale of the first message code efined in this I18N resources of specified message codes.getMessage
(@NotNull String defaultMessage, @NotNull String code, Locale locale, Object... params) Retrieves the I18N message for the specified message code and locale.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.orne.i18n.I18nResources
getMessage, getMessage
-
Constructor Details
-
I18nBundleResources
Creates a new instance for the specified bundle.- Parameters:
baseName
- The I18N resources bundle base name
-
-
Method Details
-
forBasename
Returns a non null I18N resources for the specified bundle base name. If the bundle cannot be found a dommy I18N resources is returned.- Parameters:
baseName
- The I18N resources bundle base name- Returns:
- The I18N resources instance.
-
getBundle
Returns the I18N resources bundle for the current locale.- Returns:
- The I18N resources bundle
-
getBundle
Returns the I18N resources bundle for the specified locale.- Parameters:
locale
- The desired locale- Returns:
- The I18N resources bundle
-
getMessage
@NotNull public @NotNull String getMessage(@NotNull @NotNull String defaultMessage, @NotNull @NotNull String[] codes, Locale locale, Object... params) Retrieves the I18N message for the specified locale of the first message code efined in this I18N resources of specified message codes. If no message code is defined in this I18N resources the specified default message is used. The message is formatted with the provided parameters.- Specified by:
getMessage
in interfaceI18nResources
- Parameters:
defaultMessage
- The default message formatcodes
- The message codes, in order of preferencelocale
- The locale to retrieve the message forparams
- The message parameters- Returns:
- The formatted message in the specified locale
-
getMessage
public String getMessage(@NotNull @NotNull String defaultMessage, @NotNull @NotNull String code, Locale locale, Object... params) Retrieves the I18N message for the specified message code and locale. If the message code is not defined in this I18N resources the specified default message is used. The message is formatted with the provided parameters.- Specified by:
getMessage
in interfaceI18nResources
- Parameters:
defaultMessage
- The default message formatcode
- The message codelocale
- The locale to retrieve the message forparams
- The message parameters- Returns:
- The formatted message in the specified locale
-