diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-12-03 11:01:56 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-12-03 11:01:56 -0800 |
commit | dba82120fe58d7a87973aef11bc7d85ee8ebf258 (patch) | |
tree | a0e64d31f70dd6a74f41cacbc0f17977abd0cd6f /actionview/lib/action_view/helpers/translation_helper.rb | |
parent | be5527b8e8fcc25946b128fe78db10d5bee2a483 (diff) | |
parent | 4e9dd5378bd5bfaa095a96068c7d1b7c4f47e1b0 (diff) | |
download | rails-dba82120fe58d7a87973aef11bc7d85ee8ebf258.tar.gz rails-dba82120fe58d7a87973aef11bc7d85ee8ebf258.tar.bz2 rails-dba82120fe58d7a87973aef11bc7d85ee8ebf258.zip |
Merge branch 'master-sec'
* master-sec:
Deep Munge the parameters for GET and POST
Stop using i18n's built in HTML error handling.
Ensure simple_format escapes its html attributes
Escape the unit value provided to number_to_currency
Only use valid mime type symbols as cache keys
Diffstat (limited to 'actionview/lib/action_view/helpers/translation_helper.rb')
-rw-r--r-- | actionview/lib/action_view/helpers/translation_helper.rb | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb index ad8eb47f1f..a1a2bebb6e 100644 --- a/actionview/lib/action_view/helpers/translation_helper.rb +++ b/actionview/lib/action_view/helpers/translation_helper.rb @@ -1,24 +1,14 @@ require 'action_view/helpers/tag_helper' require 'i18n/exceptions' -module I18n - class ExceptionHandler - include Module.new { - def call(exception, locale, key, options) - exception.is_a?(MissingTranslation) && options[:rescue_format] == :html ? super.html_safe : super - end - } - end -end - module ActionView # = Action View Translation Helpers module Helpers module TranslationHelper # Delegates to <tt>I18n#translate</tt> but also performs three additional functions. # - # First, it'll pass the <tt>rescue_format: :html</tt> option to I18n so that any - # thrown +MissingTranslation+ messages will be turned into inline spans that + # First, it will ensure that any thrown +MissingTranslation+ messages will be turned + # into inline spans that: # # * have a "translation-missing" class set, # * contain the missing key as a title attribute and @@ -44,8 +34,11 @@ module ActionView # naming convention helps to identify translations that include HTML tags so that # 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 the user has specified rescue_format then pass it all through, otherwise use + # raise and do the work ourselves + options[:raise] = true unless options.key?(:raise) || options.key?(:rescue_format) if html_safe_translation_key?(key) html_safe_options = options.dup options.except(*I18n::RESERVED_KEYS).each do |name, value| @@ -59,6 +52,9 @@ module ActionView else I18n.translate(scope_key_by_partial(key), options) end + rescue I18n::MissingTranslationData => e + keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) + content_tag('span', keys.last.to_s.titleize, :class => 'translation_missing', :title => "translation missing: #{keys.join('.')}") end alias :t :translate |