Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace count prop from <Trans> in translation string automatically #826

Closed
manuelbieh opened this issue Apr 15, 2019 · 2 comments
Closed

Replace count prop from <Trans> in translation string automatically #826

manuelbieh opened this issue Apr 15, 2019 · 2 comments

Comments

@manuelbieh
Copy link

@manuelbieh manuelbieh commented Apr 15, 2019

Is your feature request related to a problem? Please describe.
As already discussed on Twitter:
https://twitter.com/ManuelBieh/status/1117491118223106048

The current usage of the Trans component:

<Trans i18nKey="messageCount" count={3}>
  You have <strong>{{count: 3}}</strong> new messages.
</Trans>

with translation keys being:

messageCount: "Du hast <1>{{count}}</1> neue Nachricht",
messageCount_plural: "Du hast <1>{{count}}</1> neue Nachrichten",

feels unnecessarily complicated and also redundant if you're not using a variable for count. The value for count can possibly be replaced automatically based on the value that is passed to the count prop in the Trans component, so that this would be possible:

<Trans i18nKey="messageCount" count={3}>
  You have <strong>?</strong> new messages.
</Trans>

Describe the solution you'd like
I'd love to see this working:
https://codesandbox.io/s/oqj2o017w9

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Apr 16, 2019

works in react-i18next@10.8.0

@manuelbieh

This comment has been minimized.

Copy link
Author

@manuelbieh manuelbieh commented Apr 16, 2019

Schneller als die Feuerwehr 🚒 👨‍🚒 . Nice! Thank you!

@jamuhl jamuhl closed this Apr 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.