[Feature] Zero argument for pluralize text helper

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Feature] Zero argument for pluralize text helper

Marc Köhlbrugge
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"


Here's the code I have so far: https://github.com/marckohlbrugge/rails/commit/b939907824a74510adfa3d8f68c24a61a74a7758

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/646bbf1e-cff5-4ff4-b29e-54f944e2069c%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Zero argument for pluralize text helper

Rolandas Barysas
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"


Here's the code I have so far: https://github.com/marckohlbrugge/rails/commit/b939907824a74510adfa3d8f68c24a61a74a7758

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 [hidden email].

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/7904d4d4-a5bd-47aa-9b05-51a6050766de%40www.fastmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Zero argument for pluralize text helper

Marc Köhlbrugge
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: <a href="https://guides.rubyonrails.org/i18n.html#pluralization" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fguides.rubyonrails.org%2Fi18n.html%23pluralization\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE8-l3PbEskxCnuj0I8OiSLMT9yKQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fguides.rubyonrails.org%2Fi18n.html%23pluralization\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE8-l3PbEskxCnuj0I8OiSLMT9yKQ&#39;;return true;">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"


Here's the code I have so far: <a href="https://github.com/marckohlbrugge/rails/commit/b939907824a74510adfa3d8f68c24a61a74a7758" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmarckohlbrugge%2Frails%2Fcommit%2Fb939907824a74510adfa3d8f68c24a61a74a7758\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFV0hN1RPxS8f3ZYc-EyQM6DQnJvg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmarckohlbrugge%2Frails%2Fcommit%2Fb939907824a74510adfa3d8f68c24a61a74a7758\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFV0hN1RPxS8f3ZYc-EyQM6DQnJvg&#39;;return true;">https://github.com/marckohlbrugge/rails/commit/b939907824a74510adfa3d8f68c24a61a74a7758

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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ctNJffUaCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/646bbf1e-cff5-4ff4-b29e-54f944e2069c%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/646bbf1e-cff5-4ff4-b29e-54f944e2069c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/646bbf1e-cff5-4ff4-b29e-54f944e2069c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/646bbf1e-cff5-4ff4-b29e-54f944e2069c%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/fd18c507-b64b-4cf5-92f3-e9aa1a913014%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Zero argument for pluralize text helper

Daniel Heath-2
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 <[hidden email]> wrote:


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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/fd18c507-b64b-4cf5-92f3-e9aa1a913014%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/199AA287-D58D-4F6F-B131-90006FA6402D%40heath.cc.