diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2012-04-30 09:44:39 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2012-04-30 09:44:39 +0300 |
commit | c9f528defa38e018e542b49123d1ba048f89eaf6 (patch) | |
tree | a14f1c20150e2e3487b173797fb5bbb916481584 /actionpack/lib/action_view | |
parent | 24f143789a8989f3bccde14ff28067de25cafd87 (diff) | |
download | rails-c9f528defa38e018e542b49123d1ba048f89eaf6.tar.gz rails-c9f528defa38e018e542b49123d1ba048f89eaf6.tar.bz2 rails-c9f528defa38e018e542b49123d1ba048f89eaf6.zip |
wrap translate defaults to use translate helper features, closes #1102
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/translation_helper.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index cc74eff53a..fd06bfa2a8 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -45,6 +45,7 @@ module ActionView # you know what kind of output to expect when you call translate in a template. def translate(key, options = {}) options.merge!(:rescue_format => :html) unless options.key?(:rescue_format) + options[:default] = wrap_translate_defaults(options[:default]) if options[:default] if html_safe_translation_key?(key) html_safe_options = options.dup options.except(*I18n::RESERVED_KEYS).each do |name, value| @@ -83,6 +84,21 @@ module ActionView def html_safe_translation_key?(key) key.to_s =~ /(\b|_|\.)html$/ end + + def wrap_translate_defaults(defaults) + new_defaults = [] + defaults = Array(defaults) + while key = defaults.shift + if key.is_a?(Symbol) + new_defaults << lambda { |_, options| translate key, options.merge(:default => defaults) } + break + else + new_defautls << key + end + end + + new_defaults + end end end end |