intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.18k stars 334 forks source link

Ordinals support #1132

Open MKhasib opened 2 years ago

MKhasib commented 2 years ago

Clear and concise description of the problem

This is a follow up on discussion for supporting ordinals in V8

Suggested solution

Suggested solution is use Intl.PluralRules that has ordinals type and let's you pick up the ordinal key using a number and a locale Example:

new Intl.PluralRules('ar-EG').select(0);
// → 'zero'
new Intl.PluralRules('ar-EG').select(1);
// → 'one'
new Intl.PluralRules('ar-EG').select(2);
// → 'two'
new Intl.PluralRules('ar-EG').select(6);
// → 'few'
new Intl.PluralRules('ar-EG').select(18);
// → 'many'

We will use this keys produced by it to then select the ordinal display using suffixes schemas for ordinals across different languages that can be found here One last thing, we will inject this solution into $n to have an 'ordinal' type that returns ${{$n(number)}}${{ordinalConversion(locale,number)}}

Alternative

No response

Additional context

No response

Validations

MKhasib commented 2 years ago

@kazupon Can you please take a look and give an estimation on this feature? thanks