question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

International pluralization

See original GitHub issue

In 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:closed
  • Created 7 years ago
  • Reactions:49
  • Comments:33 (7 by maintainers)

github_iconTop GitHub Comments

33reactions
Xowapcommented, Apr 11, 2018

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 ❤️

17reactions
skyrpexcommented, Dec 14, 2016

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… 👏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found