Skip to content

Instantly share code, notes, and snippets.

@branch14
Created October 14, 2010 12:35
Show Gist options
  • Save branch14/626119 to your computer and use it in GitHub Desktop.
Save branch14/626119 to your computer and use it in GitHub Desktop.
# monkey patch I18n to log used/missing translations
I18n.module_eval do
class << self
def my_logger
filename = File.join(RAILS_ROOT, %w(log translations.log))
@my_logger ||= Logger.new(File.open(filename, 'a'))
end
def log(msg)
my_logger.info msg
end
def my_exception_handler(exception, locale, key, options)
if I18n::MissingTranslationData === exception
log exception.message
return exception.message
end
raise exception
end
# def translate(key, options = {})
# locale = options.delete(:locale) || I18n.locale
# translation = backend.translate locale, key, options
# log("found translation: (#{locale}) #{key} #{options.inspect}")
# return translation
# rescue I18n::ArgumentError => e
# raise e if options[:raise]
# my_exception_handler e, locale, key, options
# end
end
end
I18n.exception_handler = :my_exception_handler
I18n.log('started. load path...')
I18n.log(I18n.load_path * "\n")
I18n.log('logging...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment