Skip to content

Instantly share code, notes, and snippets.

@werdlerk
Created September 30, 2014 13:40
Show Gist options
  • Save werdlerk/2e787696b31b4e33e3bc to your computer and use it in GitHub Desktop.
Save werdlerk/2e787696b31b4e33e3bc to your computer and use it in GitHub Desktop.
Rails i18n key lookup tracing
# Where is Rails trying to look-up L10N / I18N Strings
# archived mirror http://cache.preserve.io/8vupog4s/index.html
# original of http://www.unixgods.org/~tilo/Rails/which_l10n_strings_is_rails_trying_to_lookup.html
#
# add newer versions to this array if the method definition didn't change, otherwise do an if-cascade
if ['0.5.0'].include?(I18n::VERSION)
module I18n
module Backend
class Simple
# Monkey-patch-in localization debugging
#
def lookup(locale, key, scope = [], options = {})
init_translations unless initialized?
keys = I18n.normalize_keys(locale, key, scope, options[:separator])
puts "\tI18N keys: #{keys}" if Rails.env.development?
keys.inject(translations) do |result, _key|
_key = _key.to_sym
return nil unless result.is_a?(Hash) && result.has_key?(_key)
result = result[_key]
result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
puts "\t => " + result.to_s + "\n\n\n" if Rails.env.development? && (result.class == String)
result
end
end
end
end
end
else
puts "\n--------------------------------------------------------------------------------"
puts "WARNING: you're using version #{I18n::VERSION} of the i18n gem."
puts " Please double check that your monkey-patch still works!"
puts " see: \"#{__FILE__}\""
puts "--------------------------------------------------------------------------------\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment