Sha256: b388ddbd76568c73def7942afb0a0b78eeceec09fbbbe62eab91d58c2659452e

Contents?: true

Size: 692 Bytes

Versions: 5

Compression:

Stored size: 692 Bytes

Contents

# Make it possible to use #localize (#l) like this:
#
#     "#{l @date}" # now returns an empty string if @date is nil
#     <%=l @date || "n.a." %>
#
# If the given object does not respond to #strftime, we just return the object itself.
module ActionView::Helpers::TranslationHelper

  def localize_with_fallback(object, options = {})
    # Duplicate the check from I18n, see https://github.com/svenfuchs/i18n/blob/v0.6.0/lib/i18n/backend/base.rb#L48
    return object unless object.respond_to?(:strftime)

    localize_without_fallback(object, options)
  end
  alias :l_with_fallback :localize_with_fallback

  alias_method_chain :localize, :fallback
  alias_method_chain :l, :fallback
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
da-suspenders-2.0.0 template/trout/config/initializers/localize_with_fallback.rb
da-suspenders-1.3.1 template/trout/config/initializers/localize_with_fallback.rb
da-suspenders-1.3.0 template/trout/config/initializers/localize_with_fallback.rb
da-suspenders-1.2.5 template/trout/config/initializers/localize_with_fallback.rb
da-suspenders-1.2.4 template/trout/config/initializers/localize_with_fallback.rb