Skip to content

Commit

Permalink
Add possibility to add supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Aug 23, 2024
1 parent e28d0a1 commit 59e6489
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions i18n-api/src/main/java/hu/blackbelt/osgi/i18n/api/I18nService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package hu.blackbelt.osgi.i18n.api;

import java.util.Locale;
import java.util.function.Supplier;

public interface I18nService {

/**
Expand All @@ -9,6 +12,14 @@ public interface I18nService {
*/
<T> T register(Class<T> clazz);

/**
* Register an i18N proxy interface to OSGi service registry. The proxy methods resolved as string to access i18n data.
*
* @param clazz
* @param localeSupplier
*/
<T> T register(Class<T> clazz, Supplier<Locale> localeSupplier);

/**
* Unregister an i18N proxy interface from OSGi service registry.
* @param clazz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ void deactivate() {

@Override
public <T> T register(Class<T> clazz) {
return register(clazz, this.localeSupplier);
}

@Override
public <T> T register(Class<T> clazz, Supplier<Locale> localeSupplier) {
MessageStreamLoader messageStreamLoader = new ClassLoaderBasedMessageStreamLoader(clazz.getClassLoader());
ClassAndRequestContextLocaleBasedMessageResolver messageResolver =
new ClassAndRequestContextLocaleBasedMessageResolver(localeSupplier, clazz, messageStreamLoader, null);
Expand Down

0 comments on commit 59e6489

Please sign in to comment.