Permalink
Browse files

Updated I18n-instructions in README; on the I18n-support for fieldset…

… titles/legends. Also clarifying some stuff.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
grimen authored and justinfrench committed Sep 16, 2009
1 parent e3b525a commit 75782e159f2dd65bcbe11312afce42f16e758943
Showing with 47 additions and 20 deletions.
  1. +47 −20 README.textile
View
@@ -258,7 +258,7 @@ h3. Label/Hint-localization
Formtastic supports localized *labels* and *hints* using the I18n API for more advanced usage. Your forms can now be DRYer and more flexible than ever, and still fully localized. This is how:
-Basic localization (labels only):
+Basic localization (labels only, with ActiveRecord):
<pre>
<% semantic_form_for @post do |form| %>
@@ -270,7 +270,7 @@ Basic localization (labels only):
*Note:* This is perfectly fine if you just want your labels to be translated using *ActiveRecord I18n attribute translations*, and you don't use input hints. But what if you do? And what if you don't want same labels in all forms?
-Enhanced localization (labels and hints):
+Enhanced localization (labels + hints + titles/legends, with Formtastic):
1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):
@@ -283,10 +283,14 @@ Enhanced localization (labels and hints):
<pre>
en:
formtastic:
+ titles:
+ post_details: "Post details"
labels:
post:
title: "Choose a title..."
body: "Write something..."
+ edit:
+ title: "Edit title"
hints:
post:
title: "Choose a good title for you post."
@@ -299,19 +303,38 @@ Enhanced localization (labels and hints):
<pre>
<% semantic_form_for @post do |form| %>
- <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
- <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
- <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
+ <% inputs do %>
+ <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
+ <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
+ <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
+ <% end %>
+ ...
<% end %>
</pre>
-4. Override I18n settings:
+4. Localized titles (a.k.a. legends):
+
+_Note: Slightly different because Formtastic can't guess how you group fields in a form._
+
+<pre>
+ <% semantic_form_for @post do |form| %>
+ <% inputs :title => :post_details do %> # => :title => "Post details"
+ # ...
+ <% end %>
+ # ...
+<% end %>
+</pre>
+
+5. Override I18n settings:
<pre>
<% semantic_form_for @post do |form| %>
- <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
- <%= form.input :body, :hint => false %> # => :label => "Write something..."
- <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
+ <% inputs do %>
+ <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
+ <%= form.input :body, :hint => false %> # => :label => "Write something..."
+ <%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
+ <% end %>
+ # ...
<% end %>
</pre>
@@ -325,25 +348,28 @@ If I18n-lookups is disabled, i.e.:
<pre>
<% semantic_form_for @post do |form| %>
- <%= form.input :title, :label => true %> # => :label => "Choose a title..."
- <%= form.input :body, :label => true %> # => :label => "Write something..."
- <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
+ <% inputs do %>
+ <%= form.input :title, :label => true %> # => :label => "Choose a title..."
+ <%= form.input :body, :label => true %> # => :label => "Write something..."
+ <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
+ <% end %>
+ # ...
<% end %>
</pre>
-5. Advanced I18n lookups
+6. Advanced I18n lookups
For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
-* @model@, e.g. "post"
-* @action@, e.g. "edit"
-* @attribute@, e.g. "title"
+* @MODEL@, e.g. "post"
+* @ACTION@, e.g. "edit"
+* @ATTRIBUTE@, e.g. "title"
...in the following order:
-1. @formtastic.{labels,hints}.MODEL.ACTION.ATTRIBUTE@ # By model and action
-2. @formtastic.{labels,hints}.MODEL.ATTRIBUTE@ # By model
-3. @formtastic.{labels,hints}.ATTRIBUTE@ # Global default
+1. @formtastic.{titles,labels,hints}.MODEL.ACTION.ATTRIBUTE@ # By model and action
+2. @formtastic.{titles,labels,hints}.MODEL.ATTRIBUTE@ # By model
+3. @formtastic.{titles,labels,hints}.ATTRIBUTE@ # Global default
...which means that you can define translations like this:
@@ -361,9 +387,10 @@ For more flexible forms; Formtastic find translations using a bottom-up approach
edit:
title: "Edit title"
body: "Edit body"
- ...
</pre>
+*Note:* For @title@: ATTRIBUTE is a KEY chosen by you, e.g. in step 4 example above: @:post_details@.
+
h2. ValidationReflection plugin
If you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin installed, you won't have to specify the :required option (it checks the validations on the model instead).

0 comments on commit 75782e1

Please sign in to comment.