Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix pluralize helper to properly handle minus one #6533

Closed
wants to merge 1 commit into from

6 participants

@jaimeiniesta

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.'

@jaimeiniesta jaimeiniesta 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
@fxn fxn was assigned
@jaimeiniesta

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
@steveklabnik
Collaborator

/cc @fxn

@carlosantoniodasilva

@fxn hey, mind taking a look? :)

@fxn
Owner

ACK!

@fxn
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.

@fxn fxn closed this
@jaimeiniesta

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!

@jaimeiniesta

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.

@arsduo

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).

@palfvin

@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?

@fxn
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
Commits on May 29, 2012
  1. @jaimeiniesta

    Fix pluralize helper to properly handle minus one

    jaimeiniesta authored
    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.'
This page is out of date. Refresh to see the latest.
View
14 actionpack/lib/action_view/helpers/text_helper.rb
@@ -161,9 +161,9 @@ def excerpt(text, phrase, options = {})
prefix + text[start_pos..end_pos].strip + postfix
end
- # Attempts to pluralize the +singular+ word unless +count+ is 1. If
- # +plural+ is supplied, it will use that when count is > 1, otherwise
- # it will use the Inflector to determine the plural form.
+ # Attempts to pluralize the +singular+ word unless +count+ is 1 or -1.
+ # If +plural+ is supplied, it will use that when count is not 1 or -1,
+ # otherwise it will use the Inflector to determine the plural form.
#
# pluralize(1, 'person')
# # => 1 person
@@ -176,8 +176,14 @@ def excerpt(text, phrase, options = {})
#
# pluralize(0, 'person')
# # => 0 people
+ #
+ # pluralize(-1, 'character')
+ # # => -1 character
+ #
+ # pluralize(-2, 'character')
+ # # => -2 characters
def pluralize(count, singular, plural = nil)
- word = if (count == 1 || count =~ /^1(\.0+)?$/)
+ word = if (count == 1 || count == -1 || count =~ /^1(\.0+)?$/)
singular
else
plural || singular.pluralize
View
2  actionpack/test/template/text_helper_test.rb
@@ -333,6 +333,8 @@ def test_pluralization
assert_equal("10 buffaloes", pluralize(10, "buffalo"))
assert_equal("1 berry", pluralize(1, "berry"))
assert_equal("12 berries", pluralize(12, "berry"))
+ assert_equal("-1 character", pluralize(-1, "character"))
+ assert_equal("-2 characters", pluralize(-2, "character"))
end
def test_cycle_class
Something went wrong with that request. Please try again.