-
-
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
Allow pluralization customization via constructor options (closes #464) #482
Conversation
This provides better pluralization customization. :D
Replace Number and Date format options with standard TS `Intl` types.
For better extensibility.
Codecov Report
@@ Coverage Diff @@
## dev #482 +/- ##
==========================================
+ Coverage 96.64% 96.66% +0.02%
==========================================
Files 9 9
Lines 655 660 +5
==========================================
+ Hits 633 638 +5
Misses 22 22
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## dev #482 +/- ##
==========================================
+ Coverage 96.64% 96.66% +0.02%
==========================================
Files 9 9
Lines 655 660 +5
==========================================
+ Hits 633 638 +5
Misses 22 22
Continue to review full report at Codecov.
|
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.
Great work!
Thanks!
Could you check my review comment please?
types/index.d.ts
Outdated
interface DateTimeFormat { [key: string]: DateTimeFormatOptions; } | ||
interface DateTimeFormats { [key: string]: DateTimeFormat; } | ||
|
||
interface DateTimeFormat { [type: string]: Intl.DateTimeFormatOptions; } |
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.
Where Intl
type definition ?
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.
It's included in ambient TS types and represents the internationalization options for toLocaleString
functions.
https://github.com/Microsoft/TypeScript/blob/eb2297df022f6b1f284aff96e93c06097bb01ea5/lib/lib.es5.d.ts#L4093
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.
Thanks!
However, In about typing change, I prefer that it's changed with another PR, because different from the this issue to be solved.
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.
Ok, I can see where you're coming from on this one, I'll revert it rn.
Closes #464.
Summary
Allows for a more civilized declarative style of defining pluralization rules via constructor options. This is needed to allow pluralization customization in environments where direct
VueI18n
prototype modification is not available (likenuxt
, for example).This PR changes the way custom pluralization would work in a backwards-compatible manner, which means - usages that utilize custom pluralization as defined in #451 will still work perfectly.
API changes
Instead of direct prototype modification it is now recommended to pass an optional
pluralizationRules
object intoVueI18n
constructor options.Very simplified example using rules for Slavic languages (Russian, Ukrainian, etc.):
This would effectively give this:
Where the format is
0 things | 1 thing | few things | multiple things
.Your template still needs to use
$tc()
, not$t()
:Which results in:
Default pluralization
If your current locale is not found in a pluralization map, the default rule of the english langugage will be used.
This is achieved by checking for current locale in a
pluralizationRules
object. If the locale is not found,VueI18n
will proceed with the old implementation.Prototype modification (as described in #451) will simply work around this concept without causing any disturbances, as demonstrated in this test.
P.S.
This is a possible minor update, essentially setting the version of
vue-i18n
to8.5.0
.