method
translate
v2.2.1 -
Show latest stable
- Class:
ActionView::Helpers::TranslationHelper
translate(key, options = {})public
No documentation available.
# File actionpack/lib/action_view/helpers/translation_helper.rb, line 6
def translate(key, options = {})
options[:raise] = true
I18n.translate(key, options)
rescue I18n::MissingTranslationData => e
keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
content_tag('span', keys.join(', '), :class => 'translation_missing')
end 1Note
Default fallback
You can specifly :default option which is useful when the translation is not found. For example:
t(:this_translation_doesnt_exist, :default => 'Ooops!')
# => Ooops!
Or even any number of "fallbacks" - the first not nil is returned:
t(:missing, :default => [:missing_too, :existing, 'Sad panda'])
# => :existing translation
Good introduction to Rails I18n is http://guides.rubyonrails.org/i18n.html