Qute and localized messages

663 views
Skip to first unread message

Alex Soto Bueno

unread,
Feb 3, 2021, 5:01:05 AM2/3/21
to Quarkus Development mailing list
Hi I've got a question, is there any way in Qute to set the localized language dynamically?  So I push a button and everything is rendered in English, I push another one and then it is in Spanish.

Alex.

Martin Kouba

unread,
Feb 3, 2021, 5:25:36 AM2/3/21
to asot...@redhat.com, Quarkus Development mailing list
Hi,

you can use a ResourceBundle in your template, and obtain the bundle
instance with one of the ResourceBundle.getBundle() methods (and pass
the relevant locale etc.).

Alternatively, you can try to use the Type-safe Message Bundles [1]. In
this case, the template variant [2] must be set as a TemplateInstance
attribute. The variant is set automatically for JAX-RS resources (in the
TemplateResponseFilter).

HTH

Martin

[1]
https://quarkus.io/guides/qute-reference#type-safe-message-bundles

[2]
https://quarkus.io/guides/qute-reference#template-variants
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/quarkus-dev/fbbcf6c6-ee26-4653-8eb4-67123aaba102n%40googlegroups.com
> <https://groups.google.com/d/msgid/quarkus-dev/fbbcf6c6-ee26-4653-8eb4-67123aaba102n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Martin Kouba
Software Engineer
Red Hat, Czech Republic

Alex Soto Bueno

unread,
Feb 3, 2021, 6:58:11 AM2/3/21
to Quarkus Development mailing list

Martin Kouba

unread,
Feb 3, 2021, 7:12:17 AM2/3/21
to asot...@redhat.com, Quarkus Development mailing list
Ah sorry, I was wrong. Type-safe messages do not honor the selected
variant which is currently only used to select the correct template
(e.g. *.txt or *.html). The correct attribute name is "locale". This
needs to be documented.

Also it would probably make sense to take the locale from the selected
variant if the "locale" attribute is not set. I'll send a PR later today...
> https://groups.google.com/d/msgid/quarkus-dev/14513f0d-c49a-4885-9bc2-59010b1ebd4fn%40googlegroups.com
> <https://groups.google.com/d/msgid/quarkus-dev/14513f0d-c49a-4885-9bc2-59010b1ebd4fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Alex Soto Bueno

unread,
Feb 3, 2021, 7:19:01 AM2/3/21
to Martin Kouba, Quarkus Development mailing list
Ok so what I need to do to make it work? Wait until a new version is released or there is a workaround? Because static annotation is not an option as it is not dynamic.

Martin Kouba

unread,
Feb 3, 2021, 7:41:17 AM2/3/21
to Alex Soto Bueno, Quarkus Development mailing list
On 03. 02. 21 13:18, Alex Soto Bueno wrote:
> Ok so what I need to do to make it work? Wait until a new version is
> released or there is a workaround?

Just replace the line [1] with:

Templates.findOwners(Collections.EMPTY_LIST).setAttribute("locale",
Locale.forLanguageTag(forLanguageTag));

[1]
https://github.com/redhat-developer-demos/quarkus-petclinic/blob/master/src/main/java/org/quarkus/samples/petclinic/owner/OwnersResource.java#L46

> Because static annotation is not an option as it is not dynamic.

I'm not quite sure what you mean here?
> >      > <mailto:quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev...@googlegroups.com>>.
> >      > To view this discussion on the web visit
> >      >
> >
> https://groups.google.com/d/msgid/quarkus-dev/fbbcf6c6-ee26-4653-8eb4-67123aaba102n%40googlegroups.com
> >
> >      >
> >
>  <https://groups.google.com/d/msgid/quarkus-dev/fbbcf6c6-ee26-4653-8eb4-67123aaba102n%40googlegroups.com?utm_medium=email&utm_source=footer>.
> >
> >
> >     --
> >     Martin Kouba
> >     Software Engineer
> >     Red Hat, Czech Republic
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Quarkus Development mailing list" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev%2Bunsu...@googlegroups.com>
> > <mailto:quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev%2Bunsu...@googlegroups.com>>.

Alex Soto Bueno

unread,
Feb 3, 2021, 8:54:50 AM2/3/21
to Martin Kouba, Quarkus Development mailing list
It worked thanks.

Martin Kouba

unread,
Feb 3, 2021, 9:17:57 AM2/3/21
to Alex Soto Bueno, Quarkus Development mailing list
Awesome!

I've created a tracking issue:
https://github.com/quarkusio/quarkus/issues/14794

Martin

On 03. 02. 21 14:53, Alex Soto Bueno wrote:
> It worked thanks.
>
> On Wed, Feb 3, 2021 at 1:41 PM Martin Kouba <mko...@redhat.com
> <mailto:mko...@redhat.com>> wrote:
>
> On 03. 02. 21 13:18, Alex Soto Bueno wrote:
> > Ok so what I need to do to make it work? Wait until a new version is
> > released or there is a workaround?
>
> Just replace the line [1] with:
>
>   Templates.findOwners(Collections.EMPTY_LIST).setAttribute("locale",
> Locale.forLanguageTag(forLanguageTag));
>
> [1]
> https://github.com/redhat-developer-demos/quarkus-petclinic/blob/master/src/main/java/org/quarkus/samples/petclinic/owner/OwnersResource.java#L46
>
>  > Because static annotation is not an option as it is not dynamic.
>
> I'm not quite sure what you mean here?
>
> >
> > On Wed, Feb 3, 2021 at 1:12 PM Martin Kouba <mko...@redhat.com
> <mailto:mko...@redhat.com>
> >     <mailto:quarkus-dev%2Bunsu...@googlegroups.com
> <mailto:quarkus-dev%252Buns...@googlegroups.com>>
> >      > <mailto:quarkus-dev...@googlegroups.com
> <mailto:quarkus-dev%2Bunsu...@googlegroups.com>
> >     <mailto:quarkus-dev%2Bunsu...@googlegroups.com
> <mailto:quarkus-dev%252Buns...@googlegroups.com>>>.
> >      > To view this discussion on the web visit
> >      >
> >
> https://groups.google.com/d/msgid/quarkus-dev/14513f0d-c49a-4885-9bc2-59010b1ebd4fn%40googlegroups.com
> >
> >      >
> >
>  <https://groups.google.com/d/msgid/quarkus-dev/14513f0d-c49a-4885-9bc2-59010b1ebd4fn%40googlegroups.com?utm_medium=email&utm_source=footer>.
> >
> >     --
> >     Martin Kouba
> >     Software Engineer
> >     Red Hat, Czech Republic
> >
>
> --
> Martin Kouba
> Software Engineer
> Red Hat, Czech Republic
>

Alex Soto Bueno

unread,
Feb 3, 2021, 9:20:48 AM2/3/21
to Martin Kouba, Quarkus Development mailing list
Great!! regarding this I was thinking if it would not be useful to create a Quarkus Qute configuration property that if it is set, then Qute automatically resolves the locale and sets it automatically. When I say automagically I am referring for example by checking the path param or header value or session attribute. 

Martin Kouba

unread,
Feb 3, 2021, 9:52:09 AM2/3/21
to Alex Soto Bueno, Quarkus Development mailing list
On 03. 02. 21 15:20, Alex Soto Bueno wrote:
> Great!! regarding this I was thinking if it would not be useful to
> create a Quarkus Qute configuration property that if it is set, then
> Qute automatically resolves the locale and sets it automatically. When I
> say automagically I am referring for example by checking the path param
> or header value or session attribute.

So I'd like to try to create a PR (see the aforementioned issue #14794)
where the locale attribute is set based on the Accept-Language header
for JAX-RS resources.

I'm not so sure about path params.

>
> On Wed, Feb 3, 2021 at 3:17 PM Martin Kouba <mko...@redhat.com
> <mailto:mko...@redhat.com>> wrote:
>
> Awesome!
>
> I've created a tracking issue:
> https://github.com/quarkusio/quarkus/issues/14794
>
> Martin
>
> On 03. 02. 21 14:53, Alex Soto Bueno wrote:
> > It worked thanks.
> >
> > On Wed, Feb 3, 2021 at 1:41 PM Martin Kouba <mko...@redhat.com
> <mailto:mko...@redhat.com>
> >      >     <mailto:quarkus-dev%2Bunsu...@googlegroups.com
> <mailto:quarkus-dev%252Buns...@googlegroups.com>
> >     <mailto:quarkus-dev%252Buns...@googlegroups.com
> <mailto:quarkus-dev%25252Bun...@googlegroups.com>>>
> >     <mailto:quarkus-dev%252Buns...@googlegroups.com
> <mailto:quarkus-dev%25252Bun...@googlegroups.com>>>>.
> >      >      > To view this discussion on the web visit
> >      >      >
> >      >
> >
> https://groups.google.com/d/msgid/quarkus-dev/14513f0d-c49a-4885-9bc2-59010b1ebd4fn%40googlegroups.com
> >      >
> >      >      >
> >      >
> >
>  <https://groups.google.com/d/msgid/quarkus-dev/14513f0d-c49a-4885-9bc2-59010b1ebd4fn%40googlegroups.com?utm_medium=email&utm_source=footer>.
> >      >
> >      >     --
> >      >     Martin Kouba
> >      >     Software Engineer
> >      >     Red Hat, Czech Republic
> >      >
> >
> >     --
> >     Martin Kouba
> >     Software Engineer
> >     Red Hat, Czech Republic
> >
>
> --
> Martin Kouba
> Software Engineer
> Red Hat, Czech Republic
>

Alex Soto Bueno

unread,
Feb 3, 2021, 9:53:35 AM2/3/21
to Martin Kouba, Quarkus Development mailing list
Ah great then.
Reply all
Reply to author
Forward
0 new messages