Pluralization with JSX Components: Security and Best Practices #1982
Replies: 1 comment 1 reply
-
Yes, that looks good to me!
Yep, the parser breaks the string into separate tokens and in case of rich tags formats them into an
It looks reasonable to me! Using a The only thing that caught my eye is if from a UX perspective you want to render "Show 0 profiles" (also not sure what would happen if you click on that). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
I’m using next-intl with t.rich() for pluralization and dynamically rendering numbers through a JSX component (e.g., an animated counter ).
Example translation in en.json:
{ "profiles": "{count, plural, =0 {Show 0 profiles} =1 {Show one profile} other {Show <counter></counter> profiles}}" }
Usage in code:
t.rich('profiles', { count: totalCount, counter: () => <AnimatedCounter value={totalCount} /> })
Questions:
Is this approach considered safe regarding XSS vulnerabilities?
Are there better syntax or patterns for this use case?
I would appreciate any advice and code examples.
Beta Was this translation helpful? Give feedback.
All reactions