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

[Feature Request] Could pluralize be dynamic based on a count argument? #58

Open
bastienboutonnet opened this issue Dec 23, 2020 · 7 comments

Comments

@bastienboutonnet
Copy link

bastienboutonnet commented Dec 23, 2020

I was wondering if there would be a case for having a version of pluralize() that could automatically decide on whether to pluralise things based on a count similar to what the inflect package does. Their API looks like this:

import inflect
p = inflect.engine()
number_of_cats = 3
print(f"I have {number_of_cats} {p.plural('cat',number_of_cats)}")

Looking at the code, I think it'd be an easy change or addition if you would rather keep pluralize() to only do plural and we could find a more generic name which could be number_agreement() or whaetever we can come up with.

I'd be more than happy to contribute to the feature if this change was welcome.

I really like your package better than inflect and would rather not add a new dependency into my tools or implement this decision every time from "scratch" in my code.

Let me know what you think.

@nickjj
Copy link

nickjj commented Apr 5, 2021

I like this idea, but since this code references Rails as an inspiration it might be best to swap your proposed arguments to match Rails' API which would be pluralize(count, singular), which would be:

error_count = 1
pluralize(error_count, "error")

I ended up implementing my own local copy of pluralize like the above with:

from inflection import pluralize as _pluralize


def pluralize(count, singular):
    if count == 1:
        return f"1 {singular}"

    return f"{count} {_pluralize(singular)}"

What do you think about adding something like that in @jpvanhal?

@bastienboutonnet
Copy link
Author

Yeah that's kind of exactly what I was thinking about. It'd be nice to have this ability IMO :) If there is anything I can help with let me know. If not looks like there's already the begining of a patch here.

@nickjj
Copy link

nickjj commented Apr 7, 2021

I'm not sure if it should be patched in directly as is because it breaks older implementations by changing the function signature and return value. For example, what if you might want the pluralized word returned without the count? This use case isn't an issue with Ruby because Ruby has a "foo.pluralize" string method to use if you don't want the count.

What do you think about maybe introducing a pluralize_count function which does the above, this way the original pluralize works as it does before and it can still be called in the new pluralize_count function.

Personally I always want the count in the use cases I've been using it for so I'm ok with either solution. Really comes down to what the maintainer of this library wants to do!

@bastienboutonnet
Copy link
Author

Good point. And yeah that was the proposal I was making with a probably badly named function that I called number_agreement.

@nickjj
Copy link

nickjj commented Apr 7, 2021

If you wanted to start a PR with my code snippet and pluralize_count function name I don't mind btw.

@bastienboutonnet
Copy link
Author

@nickjj I really don't mind either! If you don't have time I could look into it this weekend. But also, I think it might be a good idea to see if there is buy in from the maintainer. It's always annoying for them to say no after someone did some work and it's wasted time on the contributor.

What do you think?

@nickjj
Copy link

nickjj commented Apr 8, 2021

Yeah we could wait for a reply here before taking any type of action.

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

2 participants