Created
December 21, 2011 17:40
-
-
Save geronimod/1506920 to your computer and use it in GitHub Desktop.
i18n translation missing monkey patch
This file contains 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
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