Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

labels don't treat I18n name_html as html_safe

#5971

With Rails 3.0.1

generate scaffold order address:string

Place in config/locales/es.yml:

es:
  activerecord:
    models:
      order: "pedido"
    attributes:
      order:
        address_html: "Dirección"

Configure routes to set locale, and navigate to http://localhost:3000/es/orders/new

What you will see for the label for the address entry field is Dirección. Apparently f.label :address is smart enough to pick up the translation for address_html, but not smart enough to treat that text as HTML safe.

An alternative that does work:

f.label :address, t('orders.form.address_html')

Reported by Sam Ruby · November 14th, 2010 @ 08:04 PM

State: wontfix
Milestone: 3.0.5
Assigned to: José Valim José Valim
Importance: Medium

Activity

  1. Sam Ruby
    Sam Ruby

    Found a second problem. Rails provides the ability to substitute model names (e.g., es.activcerecord.models.order) and attribute names (e.g., es.activerecord.attributes.order.address). Previously, if these values were not present, the actual model and attribute names would be used.

    This still works for attribute names. For model names, a "translation_missing" message is produced. Furthermore, this messages is formatted as HTML, but is not marked as html_safe, so it appears escaped in the output.

    Examples of both problems can be seen here: http://intertwingly.net/projects/AWDwR4/checkdepot-30/section-15.3....

    Search for translation_missing and ó.

    November 14th, 2010 @ 11:03 PM

  2. Santiago Pastorino
  3. José Valim
    José Valim

    "Apparently f.label :address is smart enough to pick up the translation for address_html, but not smart enough to treat that text as HTML safe."

    This is weird, f.label should not be picking up "address_html" and I don't expect it to. I will take a look at this later and at the other bugs reported here.

    November 16th, 2010 @ 05:33 PM

  4. Aditya Sanghi
    Aditya Sanghi

    I was unable to reproduce both problems on Rails 3.0.3 / 1.8.7 / OSX

    November 16th, 2010 @ 09:40 PM

  5. Josh Kalderimis
    Josh Kalderimis

    Regarding your model names issue in your first comment, I tried to reproduce this error but could not get the "translation_missing" message to appear.

    Are you able to create a barbones rails app reproducing this issue, pop it on GitHub, then add a link to the repo in the comments here. That way we can have a look at the code and gems and see what is causing the issue.

    Thanks.

    November 17th, 2010 @ 02:38 PM

  6. Sam Ruby
    Sam Ruby
    • State changed from new to wontfix

    The "translation_missing" was an error on my part: my test make changes in the wrong order, so calls to I18n.t were introduced before the associated translations were added to the appropriate locales file. My bad.

    If f.label is not expected to pick up the _html name, then I will simply add , t('name_html') to the f.label call.

    November 20th, 2010 @ 02:57 PM

  7. Santiago Pastorino