changing translation parameter

In the @hubspot/cms-quotes-theme/templates/_locales/xx/messages.json file, there’s some translations with parameters inside:

 "invoice_after_discount": {
 "message": "after {{ discount_amount }} discount",
 "description": "",
 "placeholders": null
 },

If I use this translation key via

<p>{{template_translations.invoice_after_discount.message }}</p>

It renderes without the variable: “<p>after discount</p>”

How can I add the variable `discount_amount` to this translation key?
First thought was that there’s some filter I can apply like

<p>{{template_translations.invoice_after_discount.message|trans("discount_amount", 5) }}</p>

Hi @Anonymous

To add the discount_amount variable to the translation key, you can use the trans filter in HubL to pass the variable value while rendering the translation. Here’s an example of how you can modify the code:

<p>{{ template_translations.invoice_after_discount.message | trans(discount_amount=5) }}</p>

In the above code, 5 is the value you want to pass for the discount_amount variable. Replace 5 with the actual value you want to use.

The trans filter allows you to provide additional context or parameters for the translation. By specifying discount_amount=5, you are passing the discount_amount variable with the value of 5 to the translation. This will replace the {{ discount_amount }} placeholder in the translation string with the provided value.

Make sure you have the correct syntax and that the discount_amount variable is passed as a parameter to the trans filter. This should render the translation with the variable included, resulting in an output like <p>after 5 discount</p>.

Hope this will helps you out. Please mark it as Solution Accepted to help other Community member. Thanks!

Thank you for your reply, Gaurav! The trans filter you are mentioning does not seem to work, and I can’t find any documentation for it. When I wrote variable_name|trans() I just imagined what would be nice, I have not seen this somewhere else, so if it is a thing, it’s a wild guess.
However, as stated, this does not seem to work; |trans(variable=5) or |trans(variable, 5) or |trans(“variable”, 5).