io.quarkus.qute.i18n.MessageBundles Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-qute Show documentation
Show all versions of quarkus-qute Show documentation
Offer templating support for web, email, etc in a build time, type-safe way
package io.quarkus.qute.i18n;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CompletionStage;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Instance;
import org.jboss.logging.Logger;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.qute.Engine;
import io.quarkus.qute.EngineBuilder;
import io.quarkus.qute.EvalContext;
import io.quarkus.qute.NamespaceResolver;
import io.quarkus.qute.Resolver;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.Variant;
import io.quarkus.qute.runtime.MessageBundleRecorder.BundleContext;
public final class MessageBundles {
public static final String ATTRIBUTE_LOCALE = "locale";
public static final String DEFAULT_LOCALE = "<>";
private static final Logger LOGGER = Logger.getLogger(MessageBundles.class);
private MessageBundles() {
}
public static T get(Class bundleInterface) {
return get(bundleInterface, null);
}
public static T get(Class bundleInterface, Localized localized) {
if (!bundleInterface.isInterface()) {
throw new IllegalArgumentException("Not a message bundle interface: " + bundleInterface);
}
if (!bundleInterface.isAnnotationPresent(MessageBundle.class)
&& !bundleInterface.isAnnotationPresent(Localized.class)) {
throw new IllegalArgumentException(
"Message bundle interface must be annotated either with @MessageBundle or with @Localized: "
+ bundleInterface);
}
InstanceHandle handle = localized != null ? Arc.container().instance(bundleInterface, localized)
: Arc.container().instance(bundleInterface);
if (handle.isAvailable()) {
return handle.get();
}
throw new IllegalStateException("Unable to obtain a message bundle instance for: " + bundleInterface);
}
static void setupNamespaceResolvers(@Observes EngineBuilder builder, BundleContext context) {
// Avoid injecting "Instance
© 2015 - 2025 Weber Informatics LLC | Privacy Policy