class ActionView::Base
Public Instance Methods
translate_with_annotation(key, options={})
click to toggle source
Redefine the translate
method in ActionView
(contributed by TranslationHelper) that is context-aware of what view (or partial) is being rendered. Initial scoping will be scoped to [:controller_name :view_name]
# File lib/annotranslate.rb, line 284 def translate_with_annotation(key, options={}) # default to an empty scope scope = [] # In the case of a missing translation, fall back to letting TranslationHelper # put in span tag for a translation_missing. begin AnnoTranslate.translate_with_annotation(scope, @virtual_path, key, options.merge({:raise => true})) rescue AnnoTranslate::AnnoTranslateError, I18n::MissingTranslationData => exc # Call the original translate method str = translate_without_annotation(key, options) # View helper adds the translation missing span like: # In strict mode, do not allow TranslationHelper to add "translation missing" span like: # <span class="translation_missing">en, missing_string</span> if str =~ /span class\=\"translation_missing\"/ # In strict mode, do not allow TranslationHelper to add "translation missing" raise if AnnoTranslate.strict_mode? # Invoke callback if it is defined AnnoTranslate.missing_translation_callback(exc, key, options) end str end end