Module: SortingTableFor::I18n

Defined in:
lib/sorting_table_for/i18n.rb

Class Method Summary collapse

Class Method Details

.set_options(params, model_name, i18n_active = true) ⇒ Object

Set options to create a default scope



8
9
10
11
12
13
14
15
16
# File 'lib/sorting_table_for/i18n.rb', line 8

def set_options(params, model_name, i18n_active = true)
  @model_name, @i18n_active = model_name, i18n_active
  @action = (params.has_key? :action) ? params[:action].downcase : ''
  @controller = (params.has_key? :controller) ? params[:controller].downcase : ''
  if @controller.include? '/'
    @namespace = @controller.split '/'
    @controller = @namespace.pop
  end
end

.translate(attribute, options = {}, type = nil) ⇒ Object Also known as: t

Add a default scope if option scope isn’t defined



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sorting_table_for/i18n.rb', line 19

def translate(attribute, options = {}, type = nil)
  unless @i18n_active
    return options[:value] if options.has_key? :value
    return attribute
  end
  unless options.has_key? :scope
    options[:scope] = create_scope
    options[:scope] << TableBuilder.i18n_add_header_action_scope if type and type == :header
    options[:scope] << TableBuilder.i18n_add_footer_action_scope if type and type == :footer
    options[:scope] << options.delete(:add_scope)
    options[:scope].flatten!
  end
  ::I18n.t(attribute, options)
end