dry-rb / dry-inflector

Inflector for Ruby
https://dry-rb.org/gems/dry-inflector
MIT License
95 stars 15 forks source link

Pluralizing "people" broken #7

Closed solnic closed 6 years ago

solnic commented 6 years ago

inflector.pluralize("people") # "peoples" and I've no idea how to add a rule to make this work. When I added it to uncountable, then pluralizing "person" stopped working 😓

abinoam commented 6 years ago

@solnic I think it's working as it is.

"One person -> Two people" # "people" here is plural "The english people" -> "All peoples of the world" # "people" here is singular

See this: http://www.pearsonlongman.com/ae/azar/grammar_ex/message_board/archive/articles/00048.htm

What do you think?

solnic commented 6 years ago

Not really, it's not correct to create peoples as plural form of people, I know that in some contexts it's correct to use peoples from english grammar POV, but it's way less common and we should not do it as default inflection, also this:

irb(main):001:0> ActiveSupport::Inflector.pluralize('people')
=> "people"
irb(main):002:0> Inflecto.pluralize('people')
=> "people"
abinoam commented 6 years ago

Well, I'm not completely convinced.

If somebody provides an already plural word to a pluralize function he is providing a bad entry. The library can protect from most of the cases but not all of them. If you give 'dogs' to pluralize it'll return the same 'dogs'. But at the corner case of the word 'people' it's reasonable to the library to think "if the user is giving the word 'people' to a pluralize function that's because 'people' at this context must be a singular word and must be pluralized".

But I think you should decide on this, you're much more experienced than me. You're probably seeing implications that I'm not aware of. 👍

By the way, you're right. You should put the rule on accountables.

But It's tricky. If you put the rule on "uncountables" it'll break people -> person singularization. If you put the rule on "irregular" happens the same.

So, the way it should work is putting the rule on plural.

inflector = Dry::Inflector.new { |inflect| inflect.plural(/people\z/i, "people") }
inflector.pluralize("people") # => "people"

This is one of the rare cases where the same word has a singular meaning and a plural one.

About ActiveSupport, they have publicly stated that they wouldn't fix any inflexions rules because this would break a lot of systems that already depend on the wrong ones.

The Rails core team has stated patches for the inflections library will not be accepted in order to avoid breaking legacy applications which may be relying on errant inflections. If you discover an incorrect inflection and require it for your application or wish to define rules for languages other than English, please correct or add them yourself (explained below). Source: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html

jodosha commented 6 years ago

@solnic I'm with @abinoam

Are we going to make all the pluralizations (and singularizations) idempotent? IMO giving a string which is already pluralized is a wrong input.


However, I backported that feature from inflecto v0.0.2. https://github.com/dry-rb/dry-inflector/pull/10

Please read carefully the description of this PR ☝️

solnic commented 6 years ago

So, I closed this, I used a custom inflection rule for rom like you suggested, because you know, I can now do it since we have an instance instead of a singleton :D