public final class LabelsConstants { public static final String VEHICLEDATA_MODEL = "vehicleData.model"; public static final String REPORTTITLES_KEYDATA = "reportTitles.keyData"; ... }
How can I access the localized values now in my (type-safed) Qute templates?
Here´s my Template:
@CheckedTemplate(basePath = "") final class HtmlTemplates { ... public static native TemplateInstance keyData(
My idea is to pass a ResourceBundle and than use rb.get( LabelConstants.MY_CONSTANT) somehow in the template.
Can you point me in the right direction how to achieve this ?
What´s the recommended way to use checked Templates with values from a *.properties File ? I dont want to use String identifiers in my templates like "foo.bar" that will probably not resolve. Instead, the Constants class should be used.
Thanx, Toschder
Martin Kouba
unread,
Aug 1, 2022, 4:30:15 AM8/1/22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to tosc...@gmail.com, Quarkus Development mailing list
> in our backend project we have a /Label.properties/ as well as
> /Label_de_DE.properties/ (and more for other languages).
> I used https://github.com/kklisura/props-to-constants-generator > <https://github.com/kklisura/props-to-constants-generator> to generate
> (type-safe) constants for each key of my *.properties file:
>
> public final class LabelsConstants {
> public static final String VEHICLEDATA_MODEL = "vehicleData.model";
> public static final String REPORTTITLES_KEYDATA =
> "reportTitles.keyData";
> ...
> }
>
> How can I access the localized values now in my (type-safed) Qute templates?
>
> Here´s my Template:
>
> @CheckedTemplate(basePath = "")
> final class HtmlTemplates {
> ...
> public static native TemplateInstance keyData(
> MyItem item
> )
>
> And my template looks like:
> {@foo.bar.MyItem}
> {#title}{item.get(LabelConstants. REPORTTITLES_KEYDATA) }{/title}
>
> My idea is to pass a ResourceBundle and than use rb.get(
> LabelConstants.MY_CONSTANT) somehow in the template.
This should work. But you'll need to make the constants available in the
templates. One of the possible solutions is to annotate the
LabelsConstants class with @TemplateData [1] and then use something like
{rb.get(LabelsConstants:MY_CONSTANT)}.
> Can you point me in the right direction how to achieve this ?
> What´s the recommended way to use checked Templates with values from a
> *.properties File ? I dont want to use String identifiers in my
> templates like "foo.bar" that will probably not resolve. Instead, the
> Constants class should be used.
ResourceBundle is ok. You can also try to use the Type-safe Message
Bundles [2] but here you'd need to create the type-safe message
interface first (instead of the constants).