forked from joshmh/globalize2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
missing_translations_log_handler.rb
41 lines (37 loc) · 1.14 KB
/
missing_translations_log_handler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# A simple exception handler that behaves like the default exception handler
# but additionally logs missing translations to a given log.
#
# Useful for identifying missing translations during testing.
#
# E.g.
#
# require 'globalize/i18n/missing_translations_log_handler'
# I18n.missing_translations_logger = RAILS_DEFAULT_LOGGER
# I18n.exception_handler = :missing_translations_log_handler
#
# To set up a different log file:
#
# logger = Logger.new("#{RAILS_ROOT}/log/missing_translations.log")
# I18n.missing_translations_logger = logger
module I18n
@@missing_translations_logger = nil
class << self
def missing_translations_logger
@@missing_translations_logger ||= begin
require 'logger' unless defined?(Logger)
Logger.new(STDOUT)
end
end
def missing_translations_logger=(logger)
@@missing_translations_logger = logger
end
def missing_translations_log_handler(exception, locale, key, options)
if MissingTranslationData === exception
missing_translations_logger.warn(exception.message)
return exception.message
else
raise exception
end
end
end
end