Created
March 8, 2016 13:18
-
-
Save rafaltrojanowski/2d72dfae60e104c3687b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add newer versions to this array if the method definition didn't change, otherwise do an if-cascade | |
if ['0.7.0'].include?(I18n::VERSION) | |
module I18n | |
module Backend | |
class Simple | |
# Monkey-patch-in localization debugging.. ( see: http://www.unixgods.org/~tilo/Rails/which_l10n_strings_is_rails_trying_to_lookup.html ) | |
# Enable with ENV['I18N_DEBUG']=1 on the command line in server startup, or ./config/environments/*.rb file. | |
# | |
def lookup(locale, key, scope = [], options = {}) | |
init_translations unless initialized? | |
keys = I18n.normalize_keys(locale, key, scope, options[:separator]) | |
puts "I18N keys: #{keys}" #if ENV['I18N_DEBUG'] | |
puts "_(\"#{keys.join('.')}\")".to_s #if ENV['I18N_DEBUG'] | |
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\t => " + result.to_s + "\n" if ENV['I18N_DEBUG'] && (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 " see: http://www.unixgods.org/~tilo/Rails/which_l10n_strings_is_rails_trying_to_lookup.html" | |
puts "--------------------------------------------------------------------------------\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment