Skip to content
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

Move plural types to single npm package #105

Open
likerRr opened this issue Apr 2, 2018 · 3 comments
Open

Move plural types to single npm package #105

likerRr opened this issue Apr 2, 2018 · 3 comments

Comments

@likerRr
Copy link

likerRr commented Apr 2, 2018

What do you think of moving that part of code to a single package?

Reasons:

  1. Anyone can take it as a starting point for building whatever pluralization library
  2. It gives an ability to support locales and their pluralization logic separately from the core
  3. If you check current pull requests you can see that most of them is about locales and not about the core mechanics
@ljharb
Copy link
Collaborator

ljharb commented Apr 2, 2018

That's not a bad idea. The only thing that's used inside the rest of polyglot is pluralTypeIndex, but I'm not sure how generic that is (or how useful it would be to other libs), since it deals with the "smart_count" stuff.

@likerRr
Copy link
Author

likerRr commented Apr 2, 2018

I think it's generic enough in what it does. I see it as a module, which exports pluralTypeIndex function as default. So anyone will be able to build very basic pluralization implementation, e.g:

import getPluralTypeIndex from 'plural-type-index';

const phrases = {
	cars: ['car', 'cars'], // plural forms
};

const pluralize = (locale, phrase, count) =>
	phrase[getPluralTypeIndex(locale, count)];

pluralize('en', phrases.cars, 1); // car
pluralize('en', phrases.cars, 2); // cars

So the purpose of moving code to separate lib is to make it does one thing - get pluralization index

@WORMSS
Copy link

WORMSS commented Sep 10, 2020

One thing I would like to add to this if it goes into its own package,
The ability to query how many sections needed/recommended for each locale.

I am going to bake it into my application directly for now, eg

{
  'arabic': 6
  'bosnian_serbian': 3,
  'chinese': 1,
  ....
}

you get the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants