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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to provide default value for Trans without i18nKey #1663

Closed
nicegamer7 opened this issue Aug 22, 2023 · 1 comment 路 Fixed by #1664
Closed

Unable to provide default value for Trans without i18nKey #1663

nicegamer7 opened this issue Aug 22, 2023 · 1 comment 路 Fixed by #1664

Comments

@nicegamer7
Copy link
Contributor

nicegamer7 commented Aug 22, 2023

馃悰 Bug Report

At the company I'm working at, we're using key fallback for all of our translations as this allows us to keep the strings inside the code. We're also using the pluralize library to allow us to leave our English resource file empty.

Here's an example using t:

t('You have {{count}} message', {
  count,
  defaultValue: `You have ${count} ${pluralize('message', count)}`,
});

The above works fine with t, but does not work with the Trans component since the key defaults to the defaults prop.

To Reproduce

<Trans
  count={count}
  defaults={`You have ${count} ${pluralize('message', count)}`}
>
  You have {{ count }} message
</Trans>

Expected behavior

I expect the key to be You have {{count}} message, but the key that react-i18next uses in the t call is You have 3 messages (if count is 3, for example).

Proposed solutions

  1. (breaking change) Rather than defaulting the key to the defaults prop here, default to nodesToString(children, reactI18nextOptions).
  2. Add a defaultValue prop that behaves similar to the one in t (i.e. does not get used as the key).

I can open a PR for this if we decide on a solution.

@adrai
Copy link
Member

adrai commented Aug 22, 2023

Feel free to open a PR, but this type of pluralization handling will only work for english.
Btw. No braking change for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants