This project is archived and is in readonly mode.

#5971 ✓wontfix
Sam Ruby

labels don't treat I18n name_html as html_safe

Reported by Sam Ruby | November 14th, 2010 @ 08:04 PM | in 3.0.5

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')

Comments and changes to this ticket

  • Sam Ruby

    Sam Ruby November 14th, 2010 @ 11:03 PM

    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 ó.

  • Santiago Pastorino
  • José Valim

    José Valim November 16th, 2010 @ 05:33 PM

    "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.

  • Aditya Sanghi

    Aditya Sanghi November 16th, 2010 @ 09:40 PM

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

  • Josh Kalderimis

    Josh Kalderimis November 17th, 2010 @ 02:38 PM

    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.

  • Sam Ruby

    Sam Ruby November 20th, 2010 @ 02:57 PM

    • 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.

  • Santiago Pastorino

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages