amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

Support Rich text AND Dynamic Values #1511

Closed CarrettaRiccardo closed 1 week ago

CarrettaRiccardo commented 1 week ago

Is your feature request related to a problem? Please describe.

With the new version of next-intl (>= 3.22), there is not an option to set a rich text which also has dynamic values (the ones inside {brackets}):

To translate "preview": "Preview: <u>{username}</u>":

<RichText> {(tags) => t.rich("username.preview", { username: usernameSlugifyPreview, })} </RichText>

OR

<RichText> {(tags) => t.rich("username.preview", tags)} </RichText>

As seen above, there is no place where tags can be passed as prop, but both are needed in the i18n value.

Describe the solution you'd like

Support a new prop which allows to send rich tags AND the values to the t.rich() option, instead of using either one or the other as the second parameter

Describe alternatives you've considered

Revert to previous versions :(

amannn commented 1 week ago

You can do:

<RichText>
  {(tags) => t.rich("username", { ...tags, username })}
</RichText>

Maybe I should cover this in the docs …