Closed taehwanno closed 5 years ago
@taehwanno Thanks for your feedback!
As for adding onChanged
event, I think Provider wrapper is a better way to handle this. This is not workaround, this is how it's meant to be. We can't adjust our API to every possible i18n provider so we expose provider
component parameter as a part of our public API so that devs can adjust it to their own needs.
Anyway, adding your example to the README is a good idea.
As for direction, there is an issue with detecting the right direction #4 . I think after resolving it you won't need your own solution to it. I can make a PR today to fix it.
Also, I don't quite understand why you need to call i18n.changeLanguage(locale);
inside getDirection
? I think you should handle this inside your own provider (wrapper) that you pass as provider
.
Your PR is welcome. Thanks!
@taehwanno Also, if you are interested in a lightweight localization solution for your React app then you should take a look at https://github.com/trucknet-io/react-targem
As for adding
onChanged
event, I think Provider wrapper is a better way to handle this. This is not >workaround, this is how it's meant to be. We can't adjust our API to every possible i18n provider so > we exposeprovider
component parameter as a part of our public API so that devs can adjust it to > their own needs. Anyway, adding your example to the README is a good idea.
Thanks for the details. I understand API's purpose. I will add the example in README.
As for direction, there is an issue with detecting the right direction #4 . I think after resolving it you won't need your own solution to it. I can make a PR today to fix it.
š
Also, I don't quite understand why you need to call
i18n.changeLanguage(locale);
insidegetDirection
? I think you should handle this inside your own provider (wrapper) that you pass asprovider
.
The direction that calls i18n.changeLanguage(locale)
inside getDirection
is an example of the possible workaround directions. I think you don't have to care about it :)
Overview
About detecting of language change in react component, storybook-addon-i18n depends on
providerLocaleKey
in a storybook parameter. when a developer use react-intl, i18n addon can easily work. but about react-i18next, it doesn't support props likelocale
excepti18n
. So, additional boilerplate codes are needed.I think it's better to choice adding new API (
onChanged
detection handler?) or update the documentation in README's complex usage.Possible Directions
You can see the codes about each direction
1. Add new API (
onChanged
, the name can be changed)You can see implementation in taehwanno/storybook-addin-i18n
2. Update the documentation in README's complex usage
getDirection
workaroundgetDirection
is called every re-render, we can use this as a hook for language detection. but I think this isn't a proper direction given the original purpose ofgetDirection
API.Preferred Direction
I'm fine either way, whether in the direction of adding a new API or updating README documentation for a provider wrapper. Please give me an opinion :)