module I18nLookup
if ENV is set to true, all keys are printed on console
Protected Instance Methods
lookup(locale, key, scope = [], options = {})
click to toggle source
Calls superclass method
# File lib/i18n_lookup.rb, line 12 def lookup(locale, key, scope = [], options = {}) @@i18n_fallbacks ||= [] @@last_key ||= nil result = super(locale, key, scope, options) keys = I18n.normalize_keys(locale, key, scope, options[:separator]) if same_key?(keys) && (@@i18n_fallbacks.include?(key) || same_caller?) @@i18n_fallbacks << options[:default] @@i18n_fallbacks << key @@i18n_fallbacks.flatten! else @@last_key ||= keys.last @@i18n_fallbacks = [options[:default], key].flatten print_main_key(keys) end if result print_keys(keys, 33) print_result(result) @@last_key = nil else print_keys(keys, 31) end result end
Private Instance Methods
print_keys(keys, color_code)
click to toggle source
# File lib/i18n_lookup.rb, line 62 def print_keys(keys, color_code) $logger.debug %|\t"\e[1;#{color_code}m#{keys.map(&:to_s).join('.')}\e[0;0m"| end
print_main_key(keys, color_code = 34)
click to toggle source
# File lib/i18n_lookup.rb, line 57 def print_main_key(keys, color_code = 34) $logger.debug %|--| $logger.debug %|Key: "\e[1;#{color_code}m#{keys.last}\e[0;0m"| end
print_result(result, color_code = 35)
click to toggle source
# File lib/i18n_lookup.rb, line 66 def print_result(result, color_code = 35) $logger.debug %|\t => "\e[1;#{color_code}m#{result.to_s}\e[0;0m"| end
same_caller?()
click to toggle source
# File lib/i18n_lookup.rb, line 42 def same_caller? @@last_caller ||= caller current_caller = caller lines = current_caller.length i18n_index = current_caller.reverse.index{|line| line =~ /i18n/} start_line = lines - i18n_index result = (current_caller[start_line..-1] - @@last_caller[start_line..-1]).empty? @@last_caller = current_caller result end
same_key?(keys)
click to toggle source
# File lib/i18n_lookup.rb, line 53 def same_key?(keys) @@last_key && @@last_key.eql?(keys.last) end