react-polyglot
react-polyglot copied to clipboard
Api modernization
Hi @nayaabkhan,
Here's a PR that does the following:
- Removed componentWillReceiveProps so it's future proof. Kept the class layout in favour to function/hook layout, so polyglot can still be bound to the instance.
- Moved the
this._polyglot
calls inside an if, assumingmessages
will only need to change whenlocale
changes. This is a bit more efficient. - Introduced new prop
forceReInit
that negates above check (mimicks old default behaviour) - More tests
The second commit is a personal thing, but I think it's neater. Instead of calling translate()(Component)
you can now just call translate(Component)
. There's no initialisation going on in I18n anyway.
It's a breaking change, so I can remove it from this PR if you don't like it.
@nayaabkhan can we get the componentWillReceiveProps
removal commit?
I personally don't think there's a need to introduce a breaking API change (second commit) at this point, but it would be nice to get the modernizations in place.
@publicJorn I believe the first commit contains a few changes related to your api change, see inline comments… Would you mind having a second look? Or maybe just open another pullrequest with just the code modernization without the breaking change to increase chances we get this merged quickly? Thanks for your work!
Thanks @ctavan for the review. I fixed translate. Don't know how the tests passed, they didn't when I checked locally. But now they do. Checked the example after build, it also runs.
I discarded the api change.
@nayaabkhan are you still managing this project? I see some other PRs have been open for some time now.
Myself, I've moved to i18next, because I needed more features than polyglot could offer. But I'll leave this PR open.
@publicJorn Thanks for your PR. Yes, I do maintain this project. Unfortunately, I cannot put myself dedicatedly on this project as I work full time elsewhere. But I make sure to keep maintaining this project during the weekends.
The deprecation warning was also removed in https://github.com/nayaabkhan/react-polyglot/commit/9210c448b07c5810b97a162e297dc100c3959036 and no longer appears in [email protected]