seyhunak / twitter-bootstrap-rails

Twitter Bootstrap for Rails 6.0, Rails 5 - Rails 4.x Asset Pipeline
https://github.com/seyhunak/twitter-bootstrap-rails
4.5k stars 996 forks source link

Use count instead of pluralize #508

Closed dsimard closed 10 years ago

dsimard commented 11 years ago

In the views generated by scaffold, it would be better to use count instead of pluralize (see this line : https://github.com/seyhunak/twitter-bootstrap-rails/blob/v2.1.0/lib/generators/bootstrap/themed/templates/index.html.erb#L3).

pluralize doesn't care about the locales. Example, I have this fr.yml file :

activerecord:
  models:
    broomstick:
      one: Manche à balai
      other: Manches à balai

pluralize will display 'manche à balais' instead of 'manches à balai' as specified in the locale file.

The line should be something like :

model_class.model_name.human(count:@broomsticks.size)
toadkicker commented 11 years ago

I don't think your code would fix everyone's problem here. Does this help you: http://stackoverflow.com/questions/6166064/i18n-pluralization

dsimard commented 11 years ago

The line model_class.model_name.human(count:@broomsticks.size) will use the default translations for the model name (model_class would be Broomstick in our case) specified in the locale file as I wrote earlier.

The line model_class.model_name.human.pluralize as used in the templates doesn't pluralize it correctly (will return manche à balais with a s at the end of balai).

The line model_class.model_name.human(count:@broomsticks.size) pluralizes it correctly (will return manches à balai with a s at the end of manche).

I'm sorry if I just rewrote my issue, it's just that I don't understand why you sent me the link above and maybe we don't understand each other well. I just suggested a code change but if there's a better way of doing it, I'm really ok with that...

toadkicker commented 11 years ago

We couldn't use an instance variable here, that's why I'm gun shy on taking your suggestion here. The gem generates the template with the assumption of english. While I don't disagree with your point, I'm not concerned as its meant to be a scaffolding tool. We'd need something like

model_class.model_name.human(count:  model_class.count)

But you still have to add the translation you want and how you want to handle it either through the locales.yml or inflections. We would have to know beforehand what the model is called for it to work, as well as what the proper pluralization of it would be.