Skip to content
New issue

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

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

Already on GitHub? # to your account

Can't use default variables in Translate component without values prop #1375

Closed
andy-potts-nutmeg opened this issue Sep 16, 2021 · 4 comments

Comments

@andy-potts-nutmeg
Copy link

andy-potts-nutmeg commented Sep 16, 2021

🐛 Bug Report

Can't use default variables in the Trans component unless the values prop is defined in the Trans component.

To Reproduce

i18n.init({
  ...
  interpolation: { defaultVariables: { testValue: "Lorem ipsum" } },
});

const language = new Translations({
  language: "en-gb,
  resources: {
    common: {
      string: "Test string with default value {{testValue}}"
    }
  }
});

This can't access the default variables

<Trans
  i18n={language.i18nInstance}
  i18nKey="common.string"
/>

This can access the default variables

<Trans
  i18n={language.i18nInstance}
  i18nKey="common.string"
  vaules={{}}
/>

Expected behavior

The default variables should always be accessible in the Trans component irrespective of whether the values prop is passed into the Trans component or not

Your Environment

  • i18next version: 10.10.0
  • os: Mac
@adrai
Copy link
Member

adrai commented Sep 16, 2021

Would you like to send a Pull Request to address this? Remember to add unit tests.

@andy-potts-nutmeg andy-potts-nutmeg changed the title Can't use default variables in Translate component Can't use default variables in Translate component without values prop Sep 16, 2021
@andy-potts-nutmeg
Copy link
Author

andy-potts-nutmeg commented Sep 16, 2021

Will get back to you on this tomorrow (depends on my schedule)

@andy-potts-nutmeg
Copy link
Author

Bumping the package fixed this issue. Didn't this issue in any of the patch notes when I looked previously, must have missed it though. Thanks

@adrai
Copy link
Member

adrai commented Oct 13, 2023

indroduced in v13.3.0 #1685

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

No branches or pull requests

2 participants