Created
July 16, 2012 03:02
-
-
Save jtsagata/3120161 to your computer and use it in GitHub Desktop.
Missing translators logger and visualizer for I18n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I18n::Backend::Simple.include(I18n::Backend::Metadata) | |
| # This will work with <%= t %> , not with <%= I18n.t %> | |
| module ActionView | |
| module Helpers | |
| module TranslationHelper | |
| alias_method :translate_basic, :translate | |
| mattr_accessor :i18n_logger | |
| def translate(key, options = {}) | |
| @i18n_logger ||= Logger.new("#{Rails.root}/log/I18n.log") | |
| @i18n_logger.info "Translate key '#{key}' with options #{options.inspect}" | |
| options.merge!(:rescue_format => :html) unless options.key?(:rescue_format) | |
| options.merge!(:locale => I18n.locale) unless options.key?(:locale) | |
| reqested_locale = options[:locale].to_sym | |
| s = translate_basic(key, options) | |
| if s.translation_metadata[:locale] != reqested_locale && | |
| options[:rescue_format] == :html && Rails.env.development? | |
| @i18n_logger.error "* Translate missing for key '#{key}' with options #{options.inspect}" | |
| missing_key = I18n.normalize_keys(reqested_locale, key, options[:scope]) | |
| @i18n_logger.error "* Add key #{missing_key.join(".")}\n" | |
| %(<span class="translation_fallback" title="translation fallback #{reqested_locale}->#{s.translation_metadata[:locale]} for '#{key}'">#{s}</span>).html_safe | |
| else | |
| s | |
| end | |
| end | |
| alias :t :translate | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment