Skip to content

Instantly share code, notes, and snippets.

@geronimod
Created December 21, 2011 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geronimod/1506920 to your computer and use it in GitHub Desktop.
Save geronimod/1506920 to your computer and use it in GitHub Desktop.
i18n translation missing monkey patch
module I18nCustom
def self.included(base)
base.send :alias_method_chain, :html_message, :data_attributes
end
def html_message_with_data_attributes
keys.shift # discard the locale
key = keys.last.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
translation_key = keys.join('.')
text_to_translate = I18n.t translation_key, :locale => I18n.default_locale, :default => ''
"<span class=\"translation_missing\" data-translation-key=\"#{translation_key}\" data-translation-text=\"#{text_to_translate}\">#{key}</span>"
end
end
I18n::MissingTranslationData.send :include, I18nCustom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment