question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does this.props.i18n.t works ?

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
LFDMRcommented, Nov 27, 2017

Nice it works this way!

3reactions
panigrahcommented, Mar 15, 2018

I am getting a similar error. react-dom.production.min.js:164 TypeError: t.t is not a function when I use i18n.t. I am using withI18n() 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 with i18n._ it works.

Any ideas on what I can change?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found