]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/globalize2/lib/globalize/i18n/missing_translations_log_handler.rb
Localisation updates from http://translatewiki.net
[rails.git] / vendor / plugins / globalize2 / lib / globalize / i18n / missing_translations_log_handler.rb
1 # A simple exception handler that behaves like the default exception handler
2 # but additionally logs missing translations to a given log.
3 #
4 # Useful for identifying missing translations during testing.
5
6 # E.g. 
7 #
8 #   require 'globalize/i18n/missing_translations_log_handler
9 #   I18n.missing_translations_logger = RAILS_DEFAULT_LOGGER
10 #   I18n.exception_handler = :missing_translations_log_handler
11 #
12 # To set up a different log file:
13 #
14 #   logger = Logger.new("#{RAILS_ROOT}/log/missing_translations.log")
15 #   I18n.missing_translations_logger = logger
16
17 module I18n
18   @@missing_translations_logger = nil
19   
20   class << self
21     def missing_translations_logger
22       @@missing_translations_logger ||= begin
23         require 'logger' unless defined?(Logger)
24         Logger.new(STDOUT)
25       end
26     end
27   
28     def missing_translations_logger=(logger)
29       @@missing_translations_logger = logger
30     end
31   
32     def missing_translations_log_handler(exception, locale, key, options)
33       if MissingTranslationData === exception
34         missing_translations_logger.warn(exception.message)
35         return exception.message 
36       else
37         raise exception
38       end
39     end
40   end
41 end