Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an alternative to polyglot library with a library supporting all locales (e.g. intl-messageformat) #2307

Closed
sorjef opened this issue Sep 11, 2018 · 3 comments

Comments

@sorjef
Copy link

sorjef commented Sep 11, 2018

As react-admin uses polyglot library there is no good way to use pluralization feature for many locales. For instance, this is the case with the Ukrainian and Belarussian language. Polyglot simply does not support them. Furthermore, looks like polyglot is no longer actively supported because simple pull requests adding new locales to locale groups are not getting resolved for more than a half-year.

A great solution would be to switch to another library especially as the tree shaking feature has been implemented. A candidate might be intl-messageformat, which is used across many popular and production-ready libraries like react-intl. Furthermore, it uses official Unicode CLDR rules for pluralization as well as other official Unicode specs for locale-specific formatting.

For many use cases, there is simply no alternative ways to achieve desired behavior except forking react-admin and reimplementing i18n. For some languages, a developer can load messages under another locale which has the same pluralization rules as the target one. But this approach cannot be used if it is required to have both the target locale and the implemented locale. This is often the case with Ukrainian, Belarussian, and other Slavic languages. In the polyglot library, there is only 1 applicable pluralization algorithm — Russian plural forms. In Ukraine, it is often required to use both languages for the app Ukrainian and Russian (because of the mostly bilingual community). Hence, described workaround is not applicable.

@sorjef sorjef changed the title Replace polyglot library with a library supporting all locales (e.g. intl-messageformat) Provide an alternative to polyglot library with a library supporting all locales (e.g. intl-messageformat) Sep 12, 2018
@sorjef
Copy link
Author

sorjef commented Sep 12, 2018

As I understand replacing polyglot entirely is a very difficult task. Especially considering that many translation libraries for react-admin depend on it. A good solution might be providing some way for the user to choose another formatter programmatically.

@fzaninotto
Copy link
Member

Already discussed in #1099 (comment), and the decision we made was to not implement what you ask. See the related discussion for detailed arguments.

@kopax
Copy link
Contributor

kopax commented Apr 25, 2019

Hi @sorjef I tough you might be interested, we made react-intl function that helps you swap polyglot with react-intl.

I hoped this could be included in react-admin because it was quite easy and only needed one to two extra props.

It relies on webpack alias to tweak the import and inject a different translation provider.

The cool part was that react-admin inject a translate object in the context so source to tweak were just two. (Thanks for creating an adapter that was wise!)

It exactly do :

config.resolve.alias['./i18n/TranslationProvider'] = '@yeutech-lab/react-admin-intl/lib/ra-core/i18n/TranslationProvider';
config.resolve.alias['./TranslationContext']  = '@yeutech-lab/react-admin-intl/lib/ra-core/i18n/TranslationContext';

I've already translated EN and FR, but more language are welcome.

This will work as long as this package does not change these two imports. It will less likely happen because the translation system is already done.

/cc @fzaninotto if you do I would gladly want to be informed first, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants