[Feature] Zero argument for pluralize text helper

18 views
Skip to first unread message

Marc Köhlbrugge

unread,
Oct 2, 2019, 11:40:08 AM10/2/19
to Ruby on Rails: Core
I'm considering making a PR to add an optional "zero" argument to the pluralize text helper. This would allow you to set an alternative word for 0 (zero) when the count is zero. This is especially useful in cases where a more human "You have no bookmarks." is preferred over "You have 0 bookmarks.")

Since this would be a named parameter, I don't think it would negatively affect any existing code.

pluralize(0, "bookmark", zero: "no")
=> "no bookmarks"


Is it worth making an official PR for this?



Rolandas Barysas

unread,
Oct 2, 2019, 12:42:06 PM10/2/19
to rubyonra...@googlegroups.com
I believe you should use i18n for cases like this: https://guides.rubyonrails.org/i18n.html#pluralization

Also it's enough to add a word 'no' before people in English, but that might not be enough for other languages where you need to add that word after 'people' or change the word 'people' in general.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.

Marc Köhlbrugge

unread,
Oct 2, 2019, 3:49:30 PM10/2/19
to Ruby on Rails: Core
I wonder how many Rails apps use i18n though. I personally never use it and it seems counter intuitive to use it just for cases like these.

I didn't consider the proposed solution might not work for all languages. That's a fair point. While it does work for the handful of languages I know, I can imagine there might be some (or a lot) it wouldn't work for.

On Wednesday, October 2, 2019 at 6:42:06 PM UTC+2, Rolandas Barysas wrote:
I believe you should use i18n for cases like this: https://guides.rubyonrails.org/i18n.html#pluralization

Also it's enough to add a word 'no' before people in English, but that might not be enough for other languages where you need to add that word after 'people' or change the word 'people' in general.

On Wed, Oct 2, 2019, at 18:30, Marc Köhlbrugge wrote:
I'm considering making a PR to add an optional "zero" argument to the pluralize text helper. This would allow you to set an alternative word for 0 (zero) when the count is zero. This is especially useful in cases where a more human "You have no bookmarks." is preferred over "You have 0 bookmarks.")

Since this would be a named parameter, I don't think it would negatively affect any existing code.

pluralize(0, "bookmark", zero: "no")
=> "no bookmarks"


Is it worth making an official PR for this?




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com.

Daniel Heath

unread,
Oct 2, 2019, 4:48:03 PM10/2/19
to rubyonra...@googlegroups.com
This doesn’t work for many languages, and only works for English if you format your copy to match (ex: “you don’t have any bookmarks” vs “you have no bookmarks”)

Thanks,
Daniel Heath 

On 3 Oct 2019, at 5:49 am, Marc Köhlbrugge <marckoh...@gmail.com> wrote:


To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/fd18c507-b64b-4cf5-92f3-e9aa1a913014%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages