-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
Extendable pluralization #451
Conversation
This provides better pluralization customization. :D
Codecov Report
@@ Coverage Diff @@
## dev #451 +/- ##
=======================================
Coverage 95.98% 95.98%
=======================================
Files 9 9
Lines 647 647
=======================================
Hits 621 621
Misses 26 26
Continue to review full report at Codecov.
|
The feature is already working in production installed from my fork repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your solution. 👍
In the vue-i18n next major version, I'll plan to adopt the ICU formatting,
In the meantime, this workaround tempolary solution will be useful!!
Thanks!
Yay! I think many people would love to see this on npm. ^_^ |
Should we have some shared code for a function which supports various languages? |
@mitar, I personally think this can be left to particular implementations of "getChoiceIndex". Also, many languages do not share any pluralization rules, so there is no need to build this in the lib itself - too many edge-cases to handle. |
Hm, this document seems to be able to provide quite extensive list of those formulas, so I just wonder why we could not simply have it in code we all use. |
Because this would add unnecessary load (for most cases), increasing the size of the default code base. If I use only Russian and English in my project - why would I want to also have specific rules for Arabic and German? This is why it's better to just define these rules yourself whenever you need them by overloading getChoiceIndex. @kazupon plans to integrate the ICU formatting, which would allow for declarative definitions for those rules, making them so much easier to describe. |
@Raiondesu is there any chance to improve override for this function so it can be available from options? Could you look into my feature request? Thanks! |
@AndrewBogdanovTSS, well, this is possible... |
…or options (closes #464) (#482) by @Raiondesu * improvement(getChoiceIndex): make getChoiceIndex overridable This provides better pluralization customization. :D * update(docs): fit the new functionality * build(dist): generate dist files * revert(dist): unbuild files to correspond with guidelines * docs(pluralization): fix typo * improvement(test/unit): add test case for custom pluralization * docs(pluralization): remove unnecessary code from new pluralization example * update(types): add types for the new pluralization feature * ⚡improvement(types): remove duplicate type definitions Replace Number and Date format options with standard TS `Intl` types. * ⚡improvement(tests): Let types allow to pass getChoiceIndex into options * ⚡improvement(index): Set getChoiceIndex for current instance from opts Fixes #464 * 🐛fix(types): fix type aliases for format options * ⚡improvement(index): allow to pass a pluralization rules map instead Fixes #464 * 📃docs(api): fix md typo * ⚡improvement(types/flow): add `pluralizationRules` to the instance types * 📃docs(pluralization): add the documentation for #464 functionality * 📃docs(pluralization): fix typo * ⭐️new(test): add a test case for #464 * 📃docs(pluralization): improve custom pluralization definitions * ⭐new(test): add a test for backward compatibility with #451 and 8.4.0 * improvement(index): apply the pluralization rule to the instance For better extensibility. * 📃docs(api): improve `pluralizationRules` property definition * docs(pluralization): fix jsdoc comment misplacement * Revert "⚡improvement(types): remove duplicate type definitions" This reverts commit 286bc2e. * ⚡revert(types): Bring back original VueI18n aliases for format options
Thank you for your contribution, @Raiondesu! |
Hello. Could you please help me and tell how can I use it in nuxt app? I have all i18n config in nuxt.config.js. |
Allows custom pluralization handlers via prototype modification.
This is achieved by moving fetchChoice and getChoiceIndex functions directly into VueI18n prototype without any implementation changes. This ensures full backward-compatibility while also providing a possibility for extension to fit specific needs of specific users.
Very simplified example using rules for Slavic langauges (Russian, Ukrainian, etc.):
This would effectively allow this:
Where the format is
0 things | 1 thing | few things | multiple things
.Then:
Which results in:
Pretty much closes #78.