Does this.props.i18n.t works ?
See original GitHub issueHi, I got a state component which called a component that need translation.
class Comment extends React.Component{
render(){
<CustomTextarea
ref='textarea'
placeholder={this.props.i18n.t`Feel free to leave a comment`}
value={this.state.answer}
/>
}
}
And when I do lingui extract
I don’t have the message in my messages.json files.
BUT if I used a stateless component like this:
const TransCustomTextarea = WithI18n()(
({ i18n, props }) =>
<CustomTextarea
placeholder={i18n.t`Feel free to leave a comment`}
{...props}
/>
)
Then
class Comment extends React.Component{
render(){
<TransCustomTextarea
ref='textarea'
value={this.state.answer}
/>
}
}
Everything works.
Should I do this extra step every time ?
I use
"lingui-cli": "^1.4.2",
"lingui-i18n": "^1.3.3",
"lingui-react": "^1.4.1",
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Can't use props when passing { t } (from i18n-react) to ...
EDIT: I tried removing the { t } method and removing withNamesSpaces() HOC from the export and it all works now. But now...
Read more >withTranslation (HOC)
The withTranslation is a classic HOC (higher order component) and gets the t function and i18n instance inside your component via props.
Read more >A Guide to React Localization with i18next
React -i18next is a powerful set of components, hooks, and plugins that sit on top of i18next. Learn how to use it to...
Read more >Common i18n patterns in React
Pass this instance as i18n prop to <I18nProvider>. ... Whenever you are outside React context (i.e. you can't access props), you can use...
Read more >Common i18n patterns in React
Using jsx macros is the most straightforward way how to translate your React components. <Trans> handles translations of messages including variables and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nice it works this way!
I am getting a similar error.
react-dom.production.min.js:164 TypeError: t.t is not a function
when I usei18n.t
. I am usingwithI18n()
HOC and using compose to combine a few different HOCs together. It works fine in development but not in production.If I replace
i18n.t
withi18n._
it works.Any ideas on what I can change?