wrap translate defaults to use translate helper features #6032

Merged
merged 1 commit into from Apr 30, 2012

Conversation

Projects
None yet
3 participants
Contributor

lest commented Apr 28, 2012

Original issue #1102

actionpack/lib/action_view/helpers/translation_helper.rb
+
+ def wrap_translate_defaults(defaults)
+ Array(defaults).inject(nil) do |default, key|
+ if key.is_a? Symbol
@josevalim

josevalim Apr 28, 2012

Contributor

Maybe we should do it just if the given key ends up with html? We could even use the logic in: https://github.com/lest/rails/blob/53df3a9b198d902300d7555cd5b1dbd347f397d6/actionpack/lib/action_view/helpers/translation_helper.rb#L84

@josevalim

josevalim Apr 28, 2012

Contributor

We should also stop looping at the moment we find the first symbol key, otherwise we are converting many keys unnecessarily. You probably want to do something like this:

unsafe = []
while key = defaults.shift
  if key.is_a?(Symbol) && html_safe_translation_key?(key)
    unsafe << lambda { translate(key, defaults: defaults) }
    break
  else
    unsafe << key
  end
end
unsafe
@lest

lest Apr 30, 2012

Contributor

@josevalim I didn't check html_safe_translation_key? because translate helper do 3 different things (rescue format, scoping by partial, marking html safe). I added a test for scoping by partial test_default_lookup_scoped_by_partial.

Owner

rafaelfranca commented Apr 28, 2012

Great! @lest please put the issue number in the commit message to Github close the issue automatically.

josevalim added a commit that referenced this pull request Apr 30, 2012

Merge pull request #6032 from lest/patch-2
wrap translate defaults to use translate helper features

@josevalim josevalim merged commit 2162d16 into rails:master Apr 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment