Sha256: 69b8c5dc20330704dcfd03f3824e8ed125d516c8afa965187b7a1a04fb773897

Contents?: true

Size: 761 Bytes

Versions: 10

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

# Enables 'text to translate'.l
module StringExtension
  def localize(*args)
    sym = if args.first.is_a? Symbol
            args.shift
          else
            underscore.tr(' ', '_').gsub(/[^a-z0-9_]+/i, '').to_sym
          end
    args << { default: self }

    I18n.t(sym, *args).html_safe
  end
  alias l localize
end

String.send :include, StringExtension

# Enables :text_to_translate.l
module SymbolExtensionCustom
  def localize_with_debugging(*args)
    localized_sym = I18n.translate(self, *args)
    localized_sym.is_a?(String) ? localized_sym.html_safe : localized_sym
  end
  alias l localize_with_debugging

  def l_with_args(*args)
    l(*args).html_safe
  end
end

Symbol.send :include, SymbolExtensionCustom

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bootstrap_leather-0.10.14 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.13 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.11 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.10 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.9 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.8 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.7 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.6 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.5 lib/bootstrap_leather/localization.rb
bootstrap_leather-0.10.4 lib/bootstrap_leather/localization.rb