Module: Traco::ClassMethods

Defined in:
lib/traco/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#_locale_columns_for_attribute(attribute, fallback:) ⇒ Object

Consider this method internal.



14
15
16
# File 'lib/traco/class_methods.rb', line 14

def _locale_columns_for_attribute(attribute, fallback:)
  traco_cache(attribute, fallback: fallback).values
end

#current_locale_column(attribute) ⇒ Object



18
19
20
# File 'lib/traco/class_methods.rb', line 18

def current_locale_column(attribute)
  Traco.column(attribute, I18n.locale)
end

#human_attribute_name(column, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/traco/class_methods.rb', line 22

def human_attribute_name(column, options = {})
  attribute, locale = Traco.split_localized_column(column)

  if translates?(attribute)
    default = super(column, options.merge(default: ""))
    default.presence || "#{super(attribute, options)} (#{Traco.locale_name(locale)})"
  else
    super
  end
end

#locale_columns(*attributes) ⇒ Object



7
8
9
10
11
# File 'lib/traco/class_methods.rb', line 7

def locale_columns(*attributes)
  attributes.flat_map { |attribute|
    _locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::ANY_FALLBACK)
  }
end

#locales_for_attribute(attribute) ⇒ Object



3
4
5
# File 'lib/traco/class_methods.rb', line 3

def locales_for_attribute(attribute)
  traco_cache(attribute, fallback: LocaleFallbacks::ANY_FALLBACK).keys
end