Skip to content
This repository

Fix pluralize helper to properly handle minus one #6533

Closed
wants to merge 1 commit into from

6 participants

Jaime Iniesta Steve Klabnik Carlos Antonio da Silva Xavier Noria Alex Koppel Peter Alfvin
Jaime Iniesta

Here is a good explanation:
http://neilwhitfield.wordpress.com/2007/10/31/good-question-are-fractions-and-decimals-singular-or-plural/

'If the number one is used, whether it is +/-1, the following noun will be
singular. So it would be -1 apple. We’re talking grammar, not logic; and yes we
say zero apples, probably because zero is thought of as a number that is not
one, even though zero is neither singular nor plural logically.'

Jaime Iniesta Fix pluralize helper to properly handle minus one
Here is a good explanation:
http://neilwhitfield.wordpress.com/2007/10/31/good-question-are-fractions-and-decimals-singular-or-plural/

'If the number one is used, whether it is +/-1, the following noun will be
singular. So it would be -1 apple. We’re talking grammar, not logic; and yes we
say zero apples, probably because zero is thought of as a number that is not
one, even though zero is neither singular nor plural logically.'
74f6a92
Jaime Iniesta

Here's the real scenario that motivated this change: I've got an app where users have credits, that they can spend and recharge. There's a credit transaction log that shows these additions and substractions, like this:

 +100 credits --- initial setup
   -1 credit  --- a single action
  -25 credits --- a big action
+1000 credits --- recharged

Another possible scenario would be a twitter-like text area where you've got a count of the remaining characters. If you show the word and not just number, it should go like...

140 characters
 25 characters
  0 characters
 -1 character
 -2 characters
-30 characters
Steve Klabnik
Collaborator

/cc @fxn

Carlos Antonio da Silva

@fxn hey, mind taking a look? :)

Xavier Noria
Owner

ACK!

Xavier Noria
Owner

Yeah, I did research in the past and my conclusion was there's no right answer. You can say some sounds more natural to you than the other, but there is no authoritative English grammar about this that I am aware of.

Forums and opinion of people in the Internet is not enough, you'll find both points of view being argued, and you can also find people convinced that Elvis is alive :).

The use case you mention isn't determinant because natural language does not follow logic. for example you say two hundred, not two hundreds. Why? Because that is the way it is. Same with 0 degrees, or 0.1 grams.

So, I believe the inflector should remain the same (same resolution would have gone in the opposite situation), and your app should customize it.

Xavier Noria fxn closed this November 22, 2012
Jaime Iniesta

You're right @fxn -- the above link was the best explanation I could find but it's not an authoritative source.

So let's keep it simple and have each app customize it if needed.

Thanks!

Jaime Iniesta

Just for the record, although again not an authoritative source, this article on Wikipedia summarizes it well:

Negative numbers are usually treated the same as the corresponding positive ones: minus one degree, minus two degrees.

http://en.wikipedia.org/wiki/Plural#Usage_of_the_plural

It also talks about using the plural on decimal fractions, like 0.3 metres

I think its a simple explanation, "treat it the same as the corresponding positive ones", but as it says, it's usually treated this way, but there is no consensus.

Alex Koppel

The weather example is a great real-world use case; it's how people do speak, at least in my experience in America. My opinion is of course no more authoritative than anyone else's, but the change proposed in the PR accords with how I'd expect pluralization to work (keyed off the number itself, not its sign).

Peter Alfvin

@fxn Just read this thread and did some Google searches and while both sides of this argument are represented, the balance seems pretty solidly on the side of -1 being singular. Can you point to one or two references that you think are reasonable counters to http://english.stackexchange.com/questions/9735/is-1-singular-or-plural, Wikipedia and the totals of each from Google searches?

Xavier Noria
Owner

@palfvin The link you posted says:

"authority: as mentioned by Cawas, there is not ultimate authority on the English language, and while there are a number of references, I have not been able to identify a solid consensus on the subject."

And that was the result of my research. There is no consensus. We touch the inflector only in rare, very justified cases (actual bugs in the code and such).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 29, 2012
Jaime Iniesta Fix pluralize helper to properly handle minus one
Here is a good explanation:
http://neilwhitfield.wordpress.com/2007/10/31/good-question-are-fractions-and-decimals-singular-or-plural/

'If the number one is used, whether it is +/-1, the following noun will be
singular. So it would be -1 apple. We’re talking grammar, not logic; and yes we
say zero apples, probably because zero is thought of as a number that is not
one, even though zero is neither singular nor plural logically.'
74f6a92
This page is out of date. Refresh to see the latest.
14  actionpack/lib/action_view/helpers/text_helper.rb
@@ -161,9 +161,9 @@ def excerpt(text, phrase, options = {})
161 161
         prefix + text[start_pos..end_pos].strip + postfix
162 162
       end
163 163
 
164  
-      # Attempts to pluralize the +singular+ word unless +count+ is 1. If
165  
-      # +plural+ is supplied, it will use that when count is > 1, otherwise
166  
-      # it will use the Inflector to determine the plural form.
  164
+      # Attempts to pluralize the +singular+ word unless +count+ is 1 or -1.
  165
+      # If +plural+ is supplied, it will use that when count is not 1 or -1,
  166
+      # otherwise it will use the Inflector to determine the plural form.
167 167
       #
168 168
       #   pluralize(1, 'person')
169 169
       #   # => 1 person
@@ -176,8 +176,14 @@ def excerpt(text, phrase, options = {})
176 176
       #
177 177
       #   pluralize(0, 'person')
178 178
       #   # => 0 people
  179
+      #
  180
+      #   pluralize(-1, 'character')
  181
+      #   # => -1 character
  182
+      #
  183
+      #   pluralize(-2, 'character')
  184
+      #   # => -2 characters
179 185
       def pluralize(count, singular, plural = nil)
180  
-        word = if (count == 1 || count =~ /^1(\.0+)?$/)
  186
+        word = if (count == 1 || count == -1 || count =~ /^1(\.0+)?$/)
181 187
           singular
182 188
         else
183 189
           plural || singular.pluralize
2  actionpack/test/template/text_helper_test.rb
@@ -333,6 +333,8 @@ def test_pluralization
333 333
     assert_equal("10 buffaloes", pluralize(10, "buffalo"))
334 334
     assert_equal("1 berry", pluralize(1, "berry"))
335 335
     assert_equal("12 berries", pluralize(12, "berry"))
  336
+    assert_equal("-1 character", pluralize(-1, "character"))
  337
+    assert_equal("-2 characters", pluralize(-2, "character"))
336 338
   end
337 339
 
338 340
   def test_cycle_class
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.