Sha256: f2997fa8a68dd4e8d3e5bffdc11821e163a0120eca59a5c26dd78ad466f0badf

Contents?: true

Size: 991 Bytes

Versions: 6

Compression:

Stored size: 991 Bytes

Contents

ActionView::Helpers::TranslationHelper.module_eval do

  include Hobo::Helper::Translations::Normalizer

  # 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

6 entries across 6 versions & 1 rubygems

Version Path
hobo-1.3.0.pre26 lib/hobo/extensions/action_view/translation_helper.rb
hobo-1.3.0.pre25 lib/hobo/extensions/action_view/translation_helper.rb
hobo-1.3.0.pre24 lib/hobo/extensions/action_view/translation_helper.rb
hobo-1.3.0.pre23 lib/hobo/extensions/action_view/translation_helper.rb
hobo-1.3.0.pre22 lib/hobo/extensions/action_view/translation_helper.rb
hobo-1.3.0.pre21 lib/hobo/extensions/action_view/translation_helper.rb