I have to display a lot of texts to translate with parameters. Some parameters are dates, some are numbers, some are currencies, etc. Is there a way to "nest" the angular pipes?
I know I can create a proxy object in the component with the variable already transformed. But I'd prefer to only use these 'display' pipes in the hhtml. In a perfect world, I would have a translation:
'my_text' : "This object was bought on {{my_date | date}} for {{amount | currency}} with a discount of {{discount | percent}}"
an object:
const my_object = {my_date: new Date(), amount: 30000, discount: 0.1}
and use it in the html:
{{'my_text' | translate : my_object}}
Is there a way to do something close to this solution? A custom translate pipe maybe ?
You should write a custome pipe of your custom object not string value. Example of pipe in the format that you want:
modify your html to take parameters for localization and else:
Response will be:
Check the sandbox below: https://stackblitz.com/edit/stackblitz-starters-ja11lr?file=src%2Fmain.ts
You always can do next in html to avoid opf creating custom pipes: