Document include_blank and prompt I18n on README

This commit is contained in:
Rafael Mendonça França 2014-04-03 15:32:48 -03:00
parent 61d5a42b19
commit 91476fa57d
1 changed files with 17 additions and 5 deletions

View File

@ -611,7 +611,7 @@ end
## I18n ## I18n
**Simple Form** uses all power of I18n API to lookup labels, hints and placeholders. To customize your **Simple Form** uses all power of I18n API to lookup labels, hints, prompts and placeholders. To customize your
forms you can create a locale file like this: forms you can create a locale file like this:
```yaml ```yaml
@ -629,12 +629,18 @@ en:
user: user:
username: 'Your username' username: 'Your username'
password: '****' password: '****'
include_blanks:
user:
age: 'Rather not say'
prompts:
gender:
age: 'Select your gender'
``` ```
And your forms will use this information to render the components for you. And your forms will use this information to render the components for you.
**Simple Form** also lets you be more specific, separating lookups through actions for labels, hints and **Simple Form** also lets you be more specific, separating lookups through actions.
placeholders. Let's say you want a different label for new and edit actions, the locale file would Let's say you want a different label for new and edit actions, the locale file would
be something like: be something like:
```yaml ```yaml
@ -673,13 +679,19 @@ en:
``` ```
**Simple Form** will always look for a default attribute translation under the "defaults" key if no **Simple Form** will always look for a default attribute translation under the "defaults" key if no
specific is found inside the model key. Note that this syntax is different from 1.x. To migrate to specific is found inside the model key.
the new syntax, just move "labels.#{attribute}" to "labels.defaults.#{attribute}".
In addition, **Simple Form** will fallback to default `human_attribute_name` from Rails when no other In addition, **Simple Form** will fallback to default `human_attribute_name` from Rails when no other
translation is found for labels. Finally, you can also overwrite any label, hint or placeholder translation is found for labels. Finally, you can also overwrite any label, hint or placeholder
inside your view, just by passing the option manually. This way the I18n lookup will be skipped. inside your view, just by passing the option manually. This way the I18n lookup will be skipped.
For `:prompt` and `:include_blank` the I18n lookup is optional and to enable it is necessary to pass
`:translate` as value.
```ruby
f.input :gender, prompt: :translate
```
**Simple Form** also has support for translating options in collection helpers. For instance, given a **Simple Form** also has support for translating options in collection helpers. For instance, given a
User with a `:gender` attribute, you might want to create a select box showing translated labels User with a `:gender` attribute, you might want to create a select box showing translated labels
that would post either `male` or `female` as value. With **Simple Form** you could create an input that would post either `male` or `female` as value. With **Simple Form** you could create an input