I18n.class_eval do def self.translate(*args) options = args.last.is_a?(Hash) ? args.pop.dup : {} key = args.shift backend = config.backend locale = options.delete(:locale) || config.locale handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise enforce_available_locales!(locale) raise I18n::ArgumentError if key.is_a?(String) && key.empty? result = catch(:exception) do if key.is_a?(Array) key.map { |k| backend.translate(locale, k, options) } else backend.translate(locale, key, options) end end # For sending available translations to javascript all_translations = [] if Thread.current[:show_translation_key] == true # For array is needed just translations without tags as it would be if show_translation_key would be false Thread.current[:show_translation_key] = false I18n.available_locales.each do |l| translation = catch(:exception) do if key.is_a?(Array) all_translations.push(key.map { |k| backend.translate(l, k, options) }) else all_translations.push(backend.translate(l, key, options)) end end all_translations.push('') if translation.is_a?(I18n::MissingTranslation) end Thread.current[:show_translation_key] = true end if result.is_a?(I18n::MissingTranslation) if Thread.current[:show_translation_key] == true && !Array.wrap(options[:scope]).flatten.join('.').include?('simple_form') "#{key}".html_safe else handle_exception(handling, result, locale, key, options) end elsif result.is_a?(String) && Thread.current[:show_translation_key] && (result.present? || !Array.wrap(options[:scope]).flatten.join('.').include?('simple_form')) # Monkey patching for getting key and putting into spans s = options[:scope] if options[:scope] d = Array.wrap(options[:default]).first if options[:default] k = d if key.to_s.blank? k = [s, key].flatten.compact.join('.') "#{result}".html_safe else result.to_s.html_safe end end end