Permalink
Browse files

remove process_translate_arguments and use normalize_translation_keys…

… in default_exception_handler
  • Loading branch information...
1 parent 80a941d commit 62d063a39956887005479d1ae16cc953678a7e4d Sven Fuchs committed Jul 6, 2008
Showing with 7 additions and 13 deletions.
  1. +6 −12 lib/i18n.rb
  2. +1 −1 lib/i18n/backend/simple.rb
View
@@ -138,7 +138,9 @@ def store_translations(locale, data)
# Which is the same as using a scope option:
# I18n.t [:foo, :bar], :scope => :baz
def translate(*args)
- key, locale, options = process_translate_arguments *args
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ key = args.shift
+ locale = args.shift || options.delete(:locale) || I18n.locale
backend.translate key, locale, options
rescue I18n::ArgumentError => e
send @@exception_handler, e, key, locale, options
@@ -155,21 +157,13 @@ def localize(object, locale = nil, format = :default)
protected
def default_exception_handler(exception, key, locale, options)
if !options[:raise] and I18n::MissingTranslationData === exception
- keys = Array(options[:scope]) << key
- keys = keys.map{|key| key.to_s.split(/\./) }.flatten
- keys << 'no key' if keys.empty?
- "translation missing: #{locale}, #{keys.join(', ')}"
+ keys = normalize_translation_keys locale, key, options[:scope]
+ keys << 'no key' if keys.size < 2
+ "translation missing: #{keys.join(', ')}"
else
raise exception
end
end
-
- def process_translate_arguments(*args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- key = args.shift
- locale = args.shift || options.delete(:locale) || I18n.locale
- [key, locale, options]
- end
# Merges the given locale, key and scope into a single array of keys.
# Splits keys that contain dots into multiple keys. Makes sure all
@@ -28,7 +28,7 @@ def translate(key, locale, options = {})
reserved = :scope, :default
count, scope, default = options.values_at(:count, *reserved)
options.delete(:default)
- values = options.reject{|name, value| reserved.include? name }
+ values = options.reject{|name, value| reserved.include? name }
entry = lookup(locale, key, scope) || default(locale, default, options) || raise(I18n::MissingTranslationData.new(key, locale, options))
entry = pluralize entry, count

0 comments on commit 62d063a

Please sign in to comment.