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.392 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.393 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.391 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.390 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.389 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.388 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.387 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.386 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.385 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.384 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.382 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.381 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.376 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.375 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.374 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.372 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.368 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.367 lib/lalala/ext_i18n/input_helper.rb
lalala-4.0.0.dev.366 lib/lalala/ext_i18n/input_helper.rb
lalala-4.1.0.dev.360 lib/lalala/ext_i18n/input_helper.rb