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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder of I18N context provider instances.static interfaceInterface for configuration classes that need to set I18N context provider instances to use.static final classThe I18N context provider registry. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the I18N context for the current thread.@NotNull Locale[]Returns the supported languages.@NotNull I18nContextReturn theI18nContextassociated with the currentThread.@NotNull I18nResourcesReturns the default I18N resources.@NotNull I18nResourcesgetI18nResources(String key) Returns the I18N resources identified by the specified key.static @NotNull I18nContextProviderReturns the I18N context provider.voidInvalidates this context provider, thus invalidating any previously created I18N contexts.booleanisContextValid(@NotNull I18nContext context) Returnstrueif 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 isnullor 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 theI18nContextassociated with the currentThread.If no
I18nContextexists for the currentThreador the existing one is not alive anymore a new one is created.- Returns:
- The current
I18nContext. Nevernull.
-
isContextValid
Returnstrueif the specified context is valid or should be discarded.- Parameters:
context- The I18N context- Returns:
trueif 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.
-