Sha256: 12687c9e12abd01660e66db72c5d27585fb06d17460a9be5e2f5401060e88b01

Contents?: true

Size: 941 Bytes

Versions: 46

Compression:

Stored size: 941 Bytes

Contents

ActionView::Helpers::TranslationHelper.module_eval do

  # simple wrapper around the translate helper
  # it implements a dryml <translate> and a <t> tag
  # Improved security: interpolated variables are escaped
  # Improved management: when it returns a string it is always html_safe
  # It assumes the base translation string is html_safe
  # It removes the <span> tag when the key is missing, because it would mess up
  # the dryml tags when ht or t is used in some place

  def translate(key, options={})
    key, options = normalize_args(key, options)
    translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true))
    if translation.respond_to?(:html_safe)
      translation.html_safe
    else
      translation
    end
  rescue I18n::MissingTranslationData => e
    keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]).join('.')
    "[MISSING: #{keys}]"
  end
  alias_method :t, :translate

end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
hobo-2.2.6 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.2.5 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.2.4 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.2.3 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.2.2 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.2.1 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.2.0 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.2 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.1 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.0 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.0.pre4 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.0.pre3 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.0.pre2 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.1.0.pre1 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.0.1 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.0.0 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.0.0.pre10 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.0.0.pre9 lib/hobo/extensions/action_view/translation_helper.rb
hobo-2.0.0.pre8 lib/hobo/extensions/action_view/translation_helper.rb
hobo-1.3.3 lib/hobo/extensions/action_view/translation_helper.rb