rails/rails — pull request #16438 by agrobbin (2014-08-09 04:47:38+00:00)
Title: Add I18n support for `:placeholder` HTML option is passed to form fields

This is my first real contribution to the Rails source, so any and all feedback is appreciate!

I looked at #3674 (which appears to have been the implementation of #768), but since that was back in 2012, and there didn't appear to be any actual opposition to this addition, I'm giving this a shot against the latest master.

This adds full I18n support for the `:placeholder` HTML5 [input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-placeholder)/[textarea](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Textarea#attr-placeholder) attribute. It tries to mimic the `label` I18n support almost exactly, first checking `helpers.placeholder`, then falling back to `object.class.human_attribute_name`, then `@method_name.humanize`. It only looks attempts to check for I18n values if you pass the `:placeholder` option, as requested in the original PR.

Basic usage:
```ruby
<%= f.text_field :post, :body, placeholder: true %>
```

will look up the I18n value in this order:
```
helpers.placeholders.post.body
activerecord.attributes.post.body
attributes.body
```

I thought about extracting the common pieces from this and the `Label` tag, but thought getting feedback on the first pass would make more sense.