Module: Refinery::TranslationHelper

Defined in:
app/helpers/refinery/translation_helper.rb

Instance Method Summary collapse

Instance Method Details

#locales_with_translated_field(record, field_name, include_current: true) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/refinery/translation_helper.rb', line 18

def locales_with_translated_field(record, field_name, include_current: true)
  field_name = field_name.to_sym
  translations = record.translations.where.not(field_name => [nil, ""])
  translations = translations.where.not(locale: Refinery::I18n.default_frontend_locale.to_s) unless include_current

  translations.pluck(:locale).map(&:to_sym).sort_by do |locale|
    index = Refinery::I18n.frontend_locales.index(locale)
    index ? [0, index] : [1, locale]
  end
end

#t(key, **options) ⇒ Object

Overrides Rails’ core I18n.t() function to produce a more helpful error message. The default one wreaks havoc with CSS and makes it hard to understand the problem.



6
7
8
9
10
11
12
# File 'app/helpers/refinery/translation_helper.rb', line 6

def t(key, **options)
  if (val = super) =~ /class.+?translation_missing/
    val = val.to_s.gsub(/<span[^>]*>/, 'i18n: ').gsub('</span>', '').gsub(', ', '.')
  end

  val
end

#translated_field(record, field) ⇒ Object



14
15
16
# File 'app/helpers/refinery/translation_helper.rb', line 14

def translated_field(record, field)
  Refinery::TranslatedFieldPresenter.new(record).call(field)
end