International pluralization
See original GitHub issueIn English, pluralization looks simple: one and many. But it’s not too simple for Russian language. And there is some other languages.
i18n
means Internationalization.
I suggest to use something better for pluralization into $tc()
/Vue.tc()
.
For example, smart-plurals
.
Now I using it with Vue like this:
// pluralize.js
import Vue from 'vue'
import smartPlurals from 'smart-plurals'
export default function pluralize(string, amount, lang) {
string = Vue.t(string, lang).split(' | ')
return smartPlurals.Plurals.getRule(lang)(amount, string)
}
So I can now write different amount of plural forms for different languages in one format: singular | plural
for English or singular | few | plural
for Russian for example.
And then just pluralize('key', value, Vue.config.lang)
as a function in JS
And {{ $t('key') | pluralize(computedProperty()) }}
as a filter in templates:
<!-- module.vue -->
<script>
import filters from './filters'
export default {
filters: filters,
…
}
</script>
// filters.js
import Vue from 'vue'
import pluralize from './modules/pluralize'
export default {
pluralize: function(string, amount) {
return pluralize(string, amount, Vue.config.lang)
}
}
Other sources you can see in this repo.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:49
- Comments:33 (7 by maintainers)
Top Results From Across the Web
Intl.PluralRules - JavaScript - MDN Web Docs
Chrome Edge
PluralRules Full support. Chrome63. Toggle history Full support. Edge18. Tog...
PluralRules() constructor Full support. Chrome63. Toggle history Full support. Edge18. Tog...
resolvedOptions Full support....
Read more >Simple pluralization via `Intl.PluralRules` - 2ality
The JavaScript internationalization API can be accessed via the global variable Intl . One of its services is .PluralRules() , which determines ...
Read more >Language Plural Rules
Name Code Type Category
Afrikaans af cardinal one
Afrikaans af cardinal other
Afrikaans af ordinal other
Read more >Pluralization (p11n) - the many of plurals - LingoHub
Pluralization (p11n) is a tricky process of changing nouns from singular to plural form ... International Components for Unicode (ICU).
Read more >Plural Rules - Unicode CLDR
Languages vary in how they handle plurals of nouns or unit expressions ("hour" vs "hours", and so on). Some languages have two forms,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I find it interesting that a translation system would propose pluralization that only works in English. This kind of defeats the purpose of translating… And this ticket has been open for almost two years.
In other words, are you guys motherfucking NUTS? You reached version 7 without noticing this?! Wake the fuck up guys…
Thanks ❤️
The need of a better pluralization is there, but I think this is a bit cumbersome.
Wouldn’t it be easier if we just let the translations to use the Laravel’s pluralization format?
'apples' => '{0} There are none|[1,19] There are some|[20,Inf] There are many',
.IMO, it’s simpler and more clear. Also, we could reuse Laravel labels… 👏