<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <link>http://persumi.com/u/fredwu/tech/e/blog/t/forms</link>
    <generator>Persumi - Level up your writing and blogging with AI</generator>
    <category>Blog</category>
    <category>Tech</category>
    <pubDate>Fri, 01 May 2026 23:26:20 +0000</pubDate>
    <description/>
    <title>Blog (forms) - Fred Wu&apos;s Tech</title>
    <atom:link type="application/rss+xml" rel="self" href="http://persumi.com/u/fredwu/tech/e/blog/t/forms/feed/rss"></atom:link>
    <item>
      <pubDate>Mon, 08 Mar 2010 05:41:00 +0000</pubDate>
      <guid>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-making-i18n-forms-the-easy-way</guid>
      <comments>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-making-i18n-forms-the-easy-way</comments>
      <category>Blog</category>
      <category>Tech</category>
      <author>ifredwu@gmail.com (Fred Wu)</author>
      <description>&lt;![CDATA[&lt;p&gt;
Web applications normally have many forms. Building forms is always a mind-boggling task because it involves repetition and chaos.&lt;/p&gt;
&lt;p&gt;
A shortcut is to use a form builder / &lt;a href=&quot;http://en.wikipedia.org/wiki/Domain-specific_language&quot;&gt;DSL&lt;/a&gt;, such as &lt;a href=&quot;http://github.com/justinfrench/formtastic&quot;&gt;Formtastic&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
As I am using Rails 3, and the Rails 3 port of Formtastic isn’t complete yet, I thought I’d just use the plain vanilla Rails built-in form helper.&lt;/p&gt;
&lt;p&gt;
First of all, I am using &lt;a href=&quot;http://haml-lang.com/&quot;&gt;Haml&lt;/a&gt; instead of ERb. Already, I got the out-of-box clean looking Haml markup.&lt;/p&gt;
&lt;p&gt;
Some of you might not be aware of the fact that Rails’ built-in form helper already does i18n support.&lt;/p&gt;
&lt;p&gt;
If you have the following form:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;ruby language-ruby&quot;&gt;-form_for(@post) do |f|
  =f.label :title
  =f.text_field :title
  =f.label :body
  =f.text_area :body
  =f.submit&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
You can simply translate the labels as such in &lt;code class=&quot;inline&quot;&gt;config/locales/en.yml&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;yaml language-yaml&quot;&gt;helpers:
  label:
    post:
      title: &apos;Post Title&apos;
      body: &apos;Post Content&apos;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Better yet, I am using &lt;a href=&quot;http://r18n.rubyforge.org/&quot;&gt;r18n&lt;/a&gt; instead of i18n, so I can instead translate them in &lt;code class=&quot;inline&quot;&gt;app/i18n/en.yml&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;yaml language-yaml&quot;&gt;helpers:
  label:
    post:
      title: Post Title
      body: Post Content&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Alternatively, instead of placing the translation strings under &lt;code class=&quot;inline&quot;&gt;helpers.label&lt;/code&gt;, you may place them directly under your models, i.e. &lt;code class=&quot;inline&quot;&gt;activemodel.attribute&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;
If you’re using the &lt;a href=&quot;http://github.com/rails/rails/tree/2-3-stable&quot;&gt;Rails 2.3 stable branch&lt;/a&gt; from Github, you can also use the built-in i18n support. Although instead of &lt;code class=&quot;inline&quot;&gt;helpers.label&lt;/code&gt;, you use &lt;code class=&quot;inline&quot;&gt;views.labels&lt;/code&gt;, as seen in &lt;a href=&quot;http://github.com/rails/rails/commit/bef968d37942bfb2b7a59fca0e4451e096197c0a&quot;&gt;this commit&lt;/a&gt;.&lt;/p&gt;
]]&gt;</description>
      <link>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-making-i18n-forms-the-easy-way</link>
      <title>[Rails Tip] Making i18n Forms, the Easy Way</title>
    </item>
  </channel>
</rss>