Module: I18n

Defined in:
lib/i18n/missing_translations_log_handler.rb,
lib/i18n/missing_translations_raise_handler.rb

Overview

A simple exception handler that behaves like the default exception handler but also raises on missing translations.

Useful for identifying missing translations during testing.

E.g.

require 'globalize/i18n/missing_translations_raise_handler'
I18n.exception_handler = :missing_translations_raise_handler

Constant Summary collapse

@@missing_translations_logger =
nil

Class Method Summary collapse

Class Method Details

.missing_translations_log_handler(exception, locale, key, options) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/i18n/missing_translations_log_handler.rb', line 32

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

.missing_translations_loggerObject



21
22
23
24
25
26
# File 'lib/i18n/missing_translations_log_handler.rb', line 21

def missing_translations_logger
  @@missing_translations_logger ||= begin
    require 'logger' unless defined?(Logger)
    Logger.new(STDOUT)
  end
end

.missing_translations_logger=(logger) ⇒ Object



28
29
30
# File 'lib/i18n/missing_translations_log_handler.rb', line 28

def missing_translations_logger=(logger)
  @@missing_translations_logger = logger
end

.missing_translations_raise_handler(exception, locale, key, options) ⇒ Object



12
13
14
# File 'lib/i18n/missing_translations_raise_handler.rb', line 12

def missing_translations_raise_handler(exception, locale, key, options)
  raise exception
end