Closed rlebosse closed 8 years ago
Hey @rlebosse,
It is something I am yet to figure if it is a concern of this library or not.
Though, I think it is possible to achieve it simply by wrapping the <I18n locale={locale} messages={messages}>
tree inside a React component which maintains 2 state items for the locale
and messages
. And then passing those in this way <I18n locale={this.state.locale} messages={this.state.messages}>
. Then you could have some callback passed down the hierarchy to change the language. I'll see it I could write a demo for this.
Sorry for the double issue reference. I've tested the code in my own app, and it did work well!
Hey @rouflak, great! Thanks for the PR. I'll check it and pull if all okay soon.
Even though I18n
receives a new value for locale and messages if wrapped like in the example above, it doesn't really work because components wrapped with the translate
decorator don't re-render when the Polyglot locale changes. Any ideas, @nayaabkhan?
@sidharthachatterjee FWIW, I've tried connecting the Provider to redux
store and it seems to be working well. react-i18next
seems to be passing a changeLanguage
method down in context as well.
Hi,
@controtie Could you provide example how did you do that? I am really struggling with it. Thanks!
Do you think it would be possible to make i18n updates on the fly ?
For instance, when the app starts, currant lang is
en
and theGreeter
component displaysHello rlebosse
.But at a particular time, we decide we want to switch from
en
tofr
locale and displayBonjour rlebosse
by updating props<I18n locale={locale} messages={messages}>
.Thank you for your answer