ActionView::Helpers::TranslationHelper.translate should make values html_safe even if they were passed in through the :default hash #1102

Closed
ramontayag opened this Issue May 17, 2011 · 5 comments

5 participants

@ramontayag

In I18n, you can pass the :default option, comprised of an array with other places to look for the translation, just in case it cannot find it with the given key. The problem is that when using the html suffix in the key, ActionView::Helpers::TranslationHelper.translate doesn't check any of the default options. It only checks the given key (the first argument).

I propose translate should loop through the array of keys to search (comprised of the given key, and then the default). It can rescue the exception I18n::MissingTranslationData to continue looking through the loop until it finds a match. When it finds a match, then it can mark it as html_safe if need be. If it doesn't find a match, then it can raise that exception.

Problem, in code:

template.translate('key.that.does.not.exist', :default => 'key.that.exists.html') # returns value of `key.that.exists.html` **but** it is not `html_safe`.

What do you think? I can give a shot at doing this, but decided to run by you guys first.

@jake3030 jake3030 pushed a commit to jake3030/rails that referenced this issue Jun 28, 2011
@tekin tekin Added tests for HABTM associations with counter_sql
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1102 state:committed]
32a5cfc
@henrikhodne

I'm sorry, I'm not sure I quite understand what you're saying here. Are you reporting two bugs?

  1. translate ignores :defaults if the key ends in html
  2. translate doesn't html_safe the output if the :default key ends in html

Or is it just one of these? Or did I misinterpret you completely?

@ramontayag

2 :) But this was posted earlier this year -- not sure if it's been fixed in the later versions of Rails.

@vijaydev
Ruby on Rails member

Can you check if it is fixed in later versions ? Thanks.

@ramontayag

Will do

@rafaelfranca
Ruby on Rails member

@ramontayag what is the status of this issue. Can I close it?

@josevalim josevalim closed this in c9f528d Apr 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment