Search code examples
quarkusquarkus-qute

How to automatically select language for Qute messages


In a web app using Quarkus, RestEasy and Qute, I've successfully created a Qute template and message bundles for different languages. However, I haven't succeeded in having it select the language automatically based on the HTTP header Accept-Language.

The Qute References states:

When using quarkus-resteasy-qute the locale attribute is derived from the the Accept-Language header if not set by a user.

I'm using the quarkus-resteasy-qute extension (in pom.xml) and I can see that the Accept-Language header is set to Accept-Language: fr,en-US;q=0.7,en;q=0.3. But the page is displayed in English. So what am I missing? Is there some code I need to add?

If I explictly set the language to French (see below), it is shown in French. So the template is multi-language.

@Path("/test")
public class HomeController {
    @Location("home")
    Template homeTemplate;

    @GET
    @Produces(MediaType.TEXT_HTML)
    public TemplateInstance showHome() {
        return homeTemplate
                .instance()
                .setAttribute("locale", "fr"); // hard-coded language works
    }
}

Solution

  • The resteasy-qute integration does not support this feature yet. Feel free to create a feature request here: https://github.com/quarkusio/quarkus/issues.

    You can also try to send a PR instead ;-). This JAX-RS ContainerResponseFilter needs to be modified: https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-classic/resteasy-qute/runtime/src/main/java/io/quarkus/resteasy/qute/runtime/TemplateResponseFilter.java