title: Rails and I18n: localized templates vs localized string
body: <p>As you probably know, starting from Rails 2.2, Rails is shipped with a simple localization and internationalization backend.</p>
  
  <p>By default, you can store the strings you need to translate in the localization files within the <code>config</code> folder.</p>
  
  <pre><code>config/locales/en.yml
  config/locales/it.yml
  </code></pre>
  
  <p>But Rails provides the ability to localize templates and partials as well.
  For example, the MainController#index action can select a localized template according to the template filename and current locale settings.</p>
  
  <pre><code>apps/views/main/index.it.html.erb
  apps/views/main/index.en.html.erb
  </code></pre>
  
  <p>The first feature is useful when you need to translate single strings or short paragraphs. The latter is a good choice when the same action renders in different ways according to current locale value.</p>
  
  <p>But how do you deal with fair simple templates that share the same business logic but contains a large amount of text? Take for example the following template</p>
  
  <pre><code>&lt;% javascript_content_for :head do %&gt;
  $(function() {
    $("#choices :radio").change(function() {
      $(".choice-wizard").hide();
      $("#" + $(this).val()).show();
    });
  });
  &lt;% end %&gt;
  
  &lt;h1&gt;&lt;%= title t(".title") %&gt;&lt;/h1&gt;
  
  &lt;div class="widget"&gt;
    &lt;div class="entry form"&gt;
  
      &lt;h2&gt;&lt;%= title t(".header_choices") %&gt;&lt;/h1&gt;
  
      &lt;% form_tag "#", :id =&gt; "choices" do %&gt;
        &lt;p&gt;
          &lt;%= radio_button_tag :choice, "with" %&gt;
          &lt;%= label_tag "choice_with", "..." %&gt;
        &lt;/p&gt;
        &lt;p&gt;
          &lt;%= radio_button_tag :choice, "without" %&gt;
          &lt;%= label_tag "choice_without", "..." %&gt;
        &lt;/p&gt;
      &lt;% end %&gt;
  
      &lt;div id="with" class="choice-wizard" style="display: none;"&gt;
  
        &lt;!-- to be localized --&gt;
        &lt;h3&gt;....&lt;/h3&gt;
        &lt;p&gt;a long paragraph&lt;/p&gt;
        &lt;p&gt;a long paragraph&lt;/p&gt;
  
        &lt;p class="textcentered"&gt;
          &lt;%= link_to "Continue", new_path, :class =&gt; "button" %&gt;
        &lt;/p&gt;
        &lt;!-- / to be localized --&gt;
  
      &lt;/div&gt;
  
      &lt;div id="without" class="choice-wizard" style="display: none;"&gt;
  
        &lt;!-- to be localized --&gt;
        &lt;h3&gt;....&lt;/h3&gt;
        &lt;p&gt;a long paragraph&lt;/p&gt;
        &lt;p&gt;a long paragraph&lt;/p&gt;
  
        &lt;p class="textcentered"&gt;
          &lt;%= link_to "Continue", new_path, :class =&gt; "button" %&gt;
        &lt;/p&gt;
        &lt;!-- / to be localized --&gt;
  
      &lt;/div&gt;
  
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;% sidebar do %&gt;
    &lt;%= render :partial =&gt; "sidebar/user" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Here I have a form, a JavaScript content and a small amount of text. I need to translate the text but:</p>
  
  <ol>
  <li>the text is too long for creating a simple string in the .yml file and I don't want to end up creating O(n) strings, one for each paragraph</li>
  <li>the template contains some "features" and I don't want to create 5 template, one for each language, because it will make the app harder to maintain.</li>
  </ol>
  
  <p>How would you organize the code?</p>