Sha256: 5824abeb4290ae09cde893300d9a74e4ff8e831808ddb37ed1c1799644df78b5

Contents?: true

Size: 1.4 KB

Versions: 60

Compression:

Stored size: 1.4 KB

Contents

module Lalala::ExtI18n::InputHelper

  def input(method, options = {})
    unless translated?(method)
      return super(method, options)
    end

    begin
      _locale, _object_name = I18n.locale, @object_name

      h = "".html_safe

      locales = I18n.available_locales.dup
      locales.sort!

      if I18n.default_locale
        locales.delete(I18n.default_locale)
        locales.unshift(I18n.default_locale)
      end

      opts = options.dup
      if opts[:wrapper_html]
        opts[:wrapper_html] = opts[:wrapper_html].dup
      else
        opts[:wrapper_html] = {}
      end

      opts[:wrapper_html][:class] = [
        opts[:wrapper_html][:class],
        "translated"
      ].flatten.compact

      locales.each do |locale|
        next if Rails.application.config.lalala.i18n.excluded_locales.try(:include?, locale)
        I18n.locale  = locale
        @object_name = "#{_object_name}[translations_writer][#{locale}]"

        opts[:wrapper_html][:'data-locale'] = locale.to_s

        h << super(method, opts)
      end

      h

    ensure
      I18n.locale, @object_name = _locale, _object_name
    end
  end

protected

  def column_for(method) #:nodoc:
    if translated?(method)
      c = @object.class.translation_class.columns_hash[method.to_s]
      return c if c
    end

    super(method)
  end

  def translated?(method)
    @object.respond_to?(:translated?) and @object.translated?(method)
  end

end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
lalala-4.1.0.dev.425 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.420 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.419 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.418 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.417 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.416 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.415 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.414 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.413 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.412 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.411 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.410 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.409 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.407 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.408 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.398 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.397 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.396 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.395 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.394 lib/lalala/ext_i18n/input_helper.rb