We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Trans
defaultVariables
values
components
I was surprised to find that the Trans component does not interpolate values from defaultVariables when only the translation key is provided.
https://codesandbox.io/p/sandbox/i18-next-trans-default-variables-tq3xmv
import i18n from 'i18next' import { initReactI18next, Trans } from 'react-i18next' i18n.use(initReactI18next).init({ lng: 'en', interpolation: { defaultVariables: { name: 'Bob', }, }, resources: { en: { translation: { test: 'My name is {{name}}.', }, }, }, }) export const App = () => ( <div className="App"> <div> <Trans i18nKey="test" /> </div> <div> <Trans i18nKey="test" components={{}} /> </div> <div> <Trans i18nKey="test" values={{}} /> </div> </div> )
<Trans i18nKey="test" /> should interpolate default variables into the translation template with key test.
<Trans i18nKey="test" />
test
runtime version: Node v18, Chrome v117
i18next version: 23.5.1
react-i18next version: 13.2.2
os: macOS
refs Can't use default variables in Translate component without values prop #1375
refs Trans escapes html tags in defaultVariables if values is not specified or interpolation prefix and suffix are not specified in tOptions #1515
tOptions
The text was updated successfully, but these errors were encountered:
The workaround is to use t('test') instead of <Trans i18nKey="test"/>.
t('test')
<Trans i18nKey="test"/>
Sorry, something went wrong.
Respect defaultVariables in the interpolation options #1685
110eeae
That's a new feature... coming with v13.3.0
count
No branches or pull requests
🐛 Bug Report
I was surprised to find that the
Trans
component does not interpolate values fromdefaultVariables
when only the translation key is provided.To Reproduce
https://codesandbox.io/p/sandbox/i18-next-trans-default-variables-tq3xmv
Expected behavior
<Trans i18nKey="test" />
should interpolate default variables into the translation template with keytest
.Your Environment
runtime version: Node v18, Chrome v117
i18next version: 23.5.1
react-i18next version: 13.2.2
os: macOS
refs Can't use default variables in Translate component without values prop #1375
refs Trans escapes html tags in
defaultVariables
ifvalues
is not specified or interpolation prefix and suffix are not specified intOptions
#1515The text was updated successfully, but these errors were encountered: