lib/i18n/exceptions.rb in i18n-0.6.11 vs lib/i18n/exceptions.rb in i18n-0.7.0.beta1
- old
+ new
@@ -6,25 +6,14 @@
# was caught the handler returns an error message string containing the key/scope.
# Note that the exception handler is not called when the option :throw was given.
class ExceptionHandler
include Module.new {
def call(exception, locale, key, options)
- if exception.is_a?(MissingTranslation)
- #
- # TODO: this block is to be replaced by `exception.message` when
- # rescue_format is removed
- if options[:rescue_format] == :html
- if !defined?(@rescue_format_deprecation)
- $stderr.puts "[DEPRECATED] I18n's :recue_format option will be removed from a future release. All exception messages will be plain text. If you need the exception handler to return an html format please set or pass a custom exception handler."
- @rescue_format_deprecation = true
- end
- exception.html_message
- else
- exception.message
- end
-
- elsif exception.is_a?(Exception)
+ case exception
+ when MissingTranslation
+ exception.message
+ when Exception
raise exception
else
throw :exception, exception
end
end
@@ -56,16 +45,10 @@
def initialize(locale, key, options = nil)
@key, @locale, @options = key, locale, options.dup || {}
options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) }
end
- def html_message
- key = CGI.escapeHTML titleize(keys.last)
- path = CGI.escapeHTML keys.join('.')
- %(<span class="translation_missing" title="translation missing: #{path}">#{key}</span>)
- end
-
def keys
@keys ||= I18n.normalize_keys(locale, key, options[:scope]).tap do |keys|
keys << 'no key' if keys.size < 2
end
end
@@ -75,16 +58,9 @@
end
alias :to_s :message
def to_exception
MissingTranslationData.new(locale, key, options)
- end
-
- protected
-
- # TODO : remove when #html_message is removed
- def titleize(key)
- key.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
end
end
include Base
end