From f9a9c29fc0526a98842d78c689907ee445f24da7 Mon Sep 17 00:00:00 2001 From: Robert Csakany Date: Fri, 23 Aug 2024 10:42:39 +0200 Subject: [PATCH] Add possibility to add supplier for enum --- .../hu/blackbelt/osgi/i18n/api/EnumI18nService.java | 12 ++++++++++++ .../i18n/resourcebundle/EnumI18nServiceImpl.java | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/i18n-api/src/main/java/hu/blackbelt/osgi/i18n/api/EnumI18nService.java b/i18n-api/src/main/java/hu/blackbelt/osgi/i18n/api/EnumI18nService.java index 8651e30..0c0d61c 100644 --- a/i18n-api/src/main/java/hu/blackbelt/osgi/i18n/api/EnumI18nService.java +++ b/i18n-api/src/main/java/hu/blackbelt/osgi/i18n/api/EnumI18nService.java @@ -1,5 +1,8 @@ package hu.blackbelt.osgi.i18n.api; +import java.util.Locale; +import java.util.function.Supplier; + public interface EnumI18nService { /** @@ -9,6 +12,15 @@ public interface EnumI18nService { */ void register(Class clazz); + /** + * Register an Enum i18N message. + * + * @param clazz + * @param localeSupplier + */ + void register(Class clazz, Supplier localeSupplier); + + /** * Unregister an Enm i18n message. * @param clazz diff --git a/i18n-resourcebundle/src/main/java/hu/blackbelt/osgi/i18n/resourcebundle/EnumI18nServiceImpl.java b/i18n-resourcebundle/src/main/java/hu/blackbelt/osgi/i18n/resourcebundle/EnumI18nServiceImpl.java index bac46d9..576e9eb 100644 --- a/i18n-resourcebundle/src/main/java/hu/blackbelt/osgi/i18n/resourcebundle/EnumI18nServiceImpl.java +++ b/i18n-resourcebundle/src/main/java/hu/blackbelt/osgi/i18n/resourcebundle/EnumI18nServiceImpl.java @@ -49,6 +49,11 @@ void activate(Config config) { } public void register(Class clazz) { + register(clazz, this.localeSupplier); + } + + @Override + public void register(Class clazz, Supplier localeSupplier) { MessageStreamLoader messageStreamLoader = new ClassLoaderBasedMessageStreamLoader(clazz.getClassLoader()); ClassAndRequestContextLocaleBasedMessageResolver messageResolver = new ClassAndRequestContextLocaleBasedMessageResolver(localeSupplier, clazz, messageStreamLoader, null);