Package dev.orne.i18n.context
Interface I18nContextProvider
- All Known Implementing Classes:
AbstractI18nContextProvider
,I18nSpringContextProvider
,SharedI18nContextProvider
,ThreadI18nContextProvider
@API(status=STABLE,
since="0.1")
public interface I18nContextProvider
Provider of
I18nContext
instances. Provides methods to create new
I18n contexts, to check if a given context is still alive and to access
default I18N resources of the application.- Since:
- 0.1
- Version:
- 1.0, 2021-01
- Author:
- (w) Iker Hernaez
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Builder of I18N context provider instances.static interface
Interface for configuration classes that need to set I18N context provider instances to use.static final class
The I18N context provider registry. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the I18N context for the current thread.@NotNull Locale[]
Returns the supported languages.@NotNull I18nContext
Return theI18nContext
associated with the currentThread
.@NotNull I18nResources
Returns the default I18N resources.@NotNull I18nResources
getI18nResources
(String key) Returns the I18N resources identified by the specified key.static @NotNull I18nContextProvider
Returns the I18N context provider.void
Invalidates this context provider, thus invalidating any previously created I18N contexts.boolean
isContextValid
(@NotNull I18nContext context) Returnstrue
if the specified context is valid or should be discarded.
-
Method Details
-
getInstance
Returns the I18N context provider.- Returns:
- The I18N context provider.
-
getAvailableLocales
Returns the supported languages.- Returns:
- The supported languages
-
getDefaultI18nResources
Returns the default I18N resources.- Returns:
- The default I18N resources
-
getI18nResources
Returns the I18N resources identified by the specified key. If key isnull
or no resources is associated for such key returns the default I18N resources.- Parameters:
key
- The key of the alternative I18N resources- Returns:
- The I18N resources to use for the key
-
getContext
Return theI18nContext
associated with the currentThread
.If no
I18nContext
exists for the currentThread
or the existing one is not alive anymore a new one is created.- Returns:
- The current
I18nContext
. Nevernull
.
-
isContextValid
Returnstrue
if the specified context is valid or should be discarded.- Parameters:
context
- The I18N context- Returns:
true
if the specified context is valid
-
clearContext
void clearContext()Clears the I18N context for the current thread. -
invalidate
void invalidate()Invalidates this context provider, thus invalidating any previously created I18N contexts.Effects of calling any other method after this one is left to implementations choice, and thus is discouraged.
-