forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute message bundles: change the way message templates are loaded
- introduce a dedicated TemplateLocator so that the message templates can be reloaded automatically when a no-restart change occurs during the dev mode - fixes quarkusio#43944 (cherry picked from commit af45546)
- Loading branch information
Showing
4 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
extensions/qute/runtime/src/main/java/io/quarkus/qute/i18n/MessageTemplateLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.quarkus.qute.i18n; | ||
|
||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.util.Optional; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import io.quarkus.arc.WithCaching; | ||
import io.quarkus.qute.TemplateLocator; | ||
import io.quarkus.qute.Variant; | ||
import io.quarkus.qute.runtime.MessageBundleRecorder.BundleContext; | ||
|
||
@Singleton | ||
public class MessageTemplateLocator implements TemplateLocator { | ||
|
||
@WithCaching // BundleContext is dependent | ||
@Inject | ||
Instance<BundleContext> bundleContext; | ||
|
||
@Override | ||
public int getPriority() { | ||
return DEFAULT_PRIORITY - 1; | ||
} | ||
|
||
@Override | ||
public Optional<TemplateLocation> locate(String id) { | ||
if (bundleContext.isResolvable()) { | ||
String template = bundleContext.get().getMessageTemplates().get(id); | ||
if (template != null) { | ||
return Optional.of(new MessageTemplateLocation(template)); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
static final class MessageTemplateLocation implements TemplateLocation { | ||
|
||
private final String content; | ||
|
||
private MessageTemplateLocation(String content) { | ||
this.content = content; | ||
} | ||
|
||
@Override | ||
public Reader read() { | ||
return new StringReader(content); | ||
} | ||
|
||
@Override | ||
public Optional<Variant> getVariant() { | ||
return Optional.empty(); | ||
} | ||
|
||
} | ||
|
||
} |